JSP中执行SQL语句的问题
Class.forName("org.gjt.mm.mysql.Driver");
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/11","us","us");
PreparedStatement pstmt=con.prepareStatement("insert into contact values(?,?,?,?,?,?)");
pstmt.setString(1,"qwe")
……
pstmt.execute();
pstmt.close();
以上语句运行一切正常;
Class.forName("org.gjt.mm.mysql.Driver");
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/11","us","us");
Statement stmt=con.createStatement();
stmt.execute("insert into contact(name,mobile) values('abc',123);");
stmt.close();
con.close();
这些语句单独也运行正常,但将上面两段放在一起(如下),pstmt段仍可以执行,但下面的stmt.execute就不能执行了,请指教:
Class.forName("org.gjt.mm.mysql.Driver");
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/11","us","us");
PreparedStatement pstmt=con.prepareStatement("insert into contact values(?,?,?,?,?,?)");
pstmt.setString(1,"PWE");
……
pstmt.execute();
pstmt.close();
Statement stmt=con.createStatement();
stmt.execute("insert into contact(name,mobile) values('abc',123);");
stmt.close();
con.close();
|