Memoryizz

java 21-connetmysql

package com.inco.hive.lytest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class connet_mysql {
public static void main(String[] args) {
connet_mysql connet=new connet_mysql();
try {
connet.createsql();
} catch (Exception e) {
e.printStackTrace();
}
}

public Connection getConnection(){
Connection connection=null;
try {
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
//数据库连接url
String url="jdbc:mysql://localhost:3306/bigdata";
String user="root";
String password="123456";
connection= DriverManager.getConnection(url,user,password);
}
catch (Exception ee){
ee.printStackTrace();
}
return connection;
}
public void createsql() throws Exception {
Connection con = getConnection();
Statement st=con.createStatement();
st.execute("delete from mytableV where id=2");
st.close();
System.out.println("删除完毕");

}
}

posted on 2019-09-19 11:17  Memoryizz  阅读(180)  评论(0编辑  收藏  举报

导航