String driverName = "com.mysql.cj.jdbc.Driver";
//加載JDBC驅動
String dbURL = "jdbc:mysql://localhost:3306/javaweb_02?useSSL=false&serverTimezone=UTC";
//連接服務器和資料庫
String userName = "root"; //默認用戶名
String userPwd = "root"; //密碼
Connection conn=null;
Statement stmt=null;
try {
Class.forName(driverName);
System.out.println("連接資料庫...");
conn = DriverManager.getConnection(dbURL,userName,userPwd);
stmt=conn.createStatement();
String sql="insert into student_02(id,user,password) values(123,'無語','229324')";
int n=stmt.executeUpdate(sql);
System.out.println(n);
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
uj5u.com熱心網友回復:
資訊不夠,相關的工具類也寫一點啊轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/169839.html
標籤:Web 開發
上一篇:JDK原始碼閱讀順序
