首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MySQL PreparedStatement 应用注意

2012-11-07 
MySQL PreparedStatement 使用注意Stringsql PreparedStatementpStmtconn.prepareStatement(sql) pStmt

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

热点排行