异常如下:
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.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
我自己检查了好几遍都找不出语法错误,是在难受啊,难道是好久没有写sql造成的,折腾了大半天,最终还是找到原因了
原因如下:
先看我的写法:
PreparedStatement pstmt = null;
String querySql = "insert into base_Point (UserID,PicType,ShowType,AtPointTime,AtWarn," +
"CreateTime,DimX,DimY,LineID,PointName,Radius,RemainTime,PointType,PointAreaID)" +
" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = con.prepareStatement(querySql);
pstmt.setInt(1, Integer.valueOf(userId));
pstmt.setInt(2, Integer.valueOf(picType));
pstmt.setInt(3, Integer.valueOf(showType));
pstmt.setDate(4, new Date(new java.util.Date().getTime()));
pstmt.setInt(5, Integer.valueOf(atWarn));
pstmt.setDate(6, new Date(new java.util.Date().getTime()));
pstmt.setInt(7, Integer.valueOf(dimX));
pstmt.setInt(8, Integer.valueOf(dimY));
pstmt.setInt(9, Integer.valueOf(lineId));
pstmt.setString(10, pointName);
pstmt.setInt(11, Integer.valueOf(radius));
pstmt.setInt(12, Integer.valueOf(remainTime));
pstmt.setInt(13, Integer.valueOf(pointType));
pstmt.setInt(14, 0);
flag = pstmt.executeUpdate(querySql);