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("删除完毕");

}
}

原文地址:https://www.cnblogs.com/simly/p/11547937.html