//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
------解决方案--------------------
int rs=pstmt.executeUpdate(sql); 打断点,看执行这一步时,生成的sql是什么?
------解决方案--------------------
自己操蛋!!!
pstmt.executeUpdate();