操蛋的jdbc啊

jiaoshou3471 2014-07-15 11:46:22
//SQL插入语句
String sql=" insert into UserTb1(account,password,name,gender,age,occupation,zipcode,role,remark) values(?,?,?,?,?,?,?,?,?);";
//实例化数据库工具类
DBUtil util=new DBUtil();
//获得数据库连接
Connection conn=util.openConnection();

try
{
//创建预定义语句
PreparedStatement pstmt=conn.prepareStatement(sql);
//设置查询参数
pstmt.setString(1, account);
pstmt.setString(2, password);
pstmt.setString(3,name);
pstmt.setString(4, gender);
pstmt.setInt(5, age);
pstmt.setString(6, occupation);
pstmt.setString(7, zipcode);
pstmt.setString(8, role);
pstmt.setString(9, remark);

int rs=pstmt.executeUpdate(sql);

return rs;
}

为毛总是报错啊???
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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
...全文
128 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
shine333 2014-07-15
  • 打赏
  • 举报
回复
自己操蛋!!! pstmt.executeUpdate();
jiaoshou3471 2014-07-15
  • 打赏
  • 举报
回复
引用 5 楼 qq_16379515 的回复:
sql末“;”
不是这问题额
jiaoshou3471 2014-07-15
  • 打赏
  • 举报
回复
引用 4 楼 zhaidd 的回复:
);"…………………………
加不加;效果一样
阿克修米大 2014-07-15
  • 打赏
  • 举报
回复
sql末“;”
姜小白- 2014-07-15
  • 打赏
  • 举报
回复
int rs=pstmt.executeUpdate(sql); 打断点,看执行这一步时,生成的sql是什么?
jiaoshou3471 2014-07-15
  • 打赏
  • 举报
回复
在数据库里插入没有问题。。。
jiaoshou3471 2014-07-15
  • 打赏
  • 举报
回复
坑爹啊,老是这种错误,好浪费时间,,,,
jiaoshou3471 2014-07-15
  • 打赏
  • 举报
回复
引用 8 楼 shine333 的回复:
自己操蛋!!! pstmt.executeUpdate();
这提示,一直以为是句子语法错误,没注意pstmt.executeUpdate(),泪奔啊。。。 大神骂的好。。。

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧