打印

[Java] JSP中执行SQL语句的问题

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();

TOP

不要在jsp里写那么多代码

TOP

不知道pstmt.execute();这一句的前面还有什么语句?

TOP

error message
[img]http://img467.imageshack.us/img467/6695/b4115459wu.jpg[/img]

TOP

什么出错信息啊

TOP

............

提示: 作者被禁止或删除 内容自动屏蔽

TOP

引用:
原帖由 javalod 于 2008-6-12 09:41 发表
如果你已经是稍有水平开发者,你就应该始终以PreparedStatement代替Statement.也就是说,在任何时候都不要使用Statement
同意

TOP

楼主问题提的确实好

提示: 作者被禁止或删除 内容自动屏蔽

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-12-3 08:45 京ICP证060528 号

Designed By 17DST