增,删,改

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     }
posted @ 2018-03-27 16:41  流去  阅读(135)  评论(0编辑  收藏  举报