JDBC 数据库连接池

jdbc的链接

//1. 导入数据库驱动

Class.forName("com.mysql.jdbc.Driver");

//2.获取连接对象
try{
String url = "jdbc:mysql://localhost:3306/student?useSSL=false";// 获取数据库连接地址
String username = "root";
String password ="123456";
Connection conn = DriverManager.getConnection(url,username,password);
Statement stmt = conn.createStatement();
// 执行sql 语句
stmt.execute("insert into t_user (id,user_name) values (12,"测试"));
// 3. 关闭连接 释放内存资源 节约性能
stmt.close();
conn.close();
}catch(Exception e){
}

posted @ 2022-12-08 18:51  子离离  阅读(68)  评论(0)    收藏  举报