真的是好久没有用过jdbc连接池去加载mysql驱动连接数据库了 今天偶尔一些都忘得差不多了
温习一下 巩固基础
String URL="jdbc:mysql://localhost:3306/opc?characterEncoding=utf-8";
String USER="root";
String PASSWORD="root";
try{
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
//链接数据库
Connection connection=DriverManager.getConnection(URL,USER,PASSWORD);
String sql="insert into user(username,password) values(?,1)";
PreparedStatement pds=connection.prepareStatement(sql);
pds.setString(1, "xqq");
pds.execute();
pds.close();
connection.close();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}