读书人

MySQL PreparedStatement 应用注意

发布时间: 2012-11-07 09:56:10 作者: rapoo

MySQL PreparedStatement 使用注意
String sql;
PreparedStatement pStmt=conn.prepareStatement(sql);
pStmt.setShort(1,(short)10)
pStmt.setString(2, "test ");

pStmt.executeUpdate(sql); //出现Exception

ava.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 "

这个问题是由于最后pStmt.executeUpdate是不能带参数的。应该直接用。
pStmt.executeUpdate();

读书人网 >Mysql

热点推荐