JDBC学习

笔记如上
学了个代码
import java.sql.*;
public class jdbc01 {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//注册驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//获取连接
conn = DriverManager.getConnection("jdbc:mysql//localhost:3306/student", "root", "123456");
//执行SQL
String insertSql = "insert into dept(deptno,dname,loc) values(01,'第一','m',20)";
stmt.executeUpdate(insertSql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
}
}
因为配置idea没整明白,所以代码还没运行起来

浙公网安备 33010602011771号