public static void main(String[] args) throws ClassNotFoundException, SQLException {
14 String URL="jdbc:mysql://127.0.0.1:3306/imooc?useUnicode=true&characterEncoding=utf-8";
15 String USER="root";
16 String PASSWORD="tiger";
17 //1.加载驱动程序
18 Class.forName("com.mysql.jdbc.Driver");
19 //2.获得数据库链接
20 Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);
21 //3.通过数据库的连接操作数据库,实现增删改查(使用Statement类)
22 String s=""+"insert into user(id,user_name,user_password) values("+"2,?,123)";
23 PreparedStatement pst=conn.prepareStatement(s);
24
25 pst.setString(1, "xiaoshuai1");
26 //pst.setString(2, "123");
27
28 pst.execute();
29 //关闭资源
30 pst.close();
31 conn.close();
32 }