MySQL PreparedStatement 应用注意

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 PreparedStatement 应用注意

相关文章:

你感兴趣的文章:

标签云: