java jdbc报错
PreparedStatement preStmt=null; int rs=0; String sql = "INSERT INTO hr_role nc_id,name values ?,?"; Set<String> key = map.keySet; for Iterator<String> it = key.iterator; it.hasNext; { String number = it.next; System.out.printlnnumber + ":" + map.getnumber; try { preStmt= conn.prepareStatementsql; preStmt.setInt1, Integer.parseIntnumber; preStmt.setString2, map.getnumber; rs=preStmt.executeUpdatesql; } catch Exception e { e.printStackTrace; } }
每次执行都会报错
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
at sun.reflect.GeneratedConstructorAccessor7.newInstanceUnknown Source
map中都是有值的 sql语法也没错,那是什么问题啊?谢谢
rs=preStmt.executeUpdatesql;
这句改成
rs=preStmt.executeUpdate;
executeUpdateString SQL执行的静态的SQL语句,其实你是执行了INSERT INTO hr_role nc_id,name values ?,?
,就抛出了mysql 语法错误
发表评论