java 使用jdbc调用MYSQL 遇到一个诡异的坑,同样的插入语句,总是报语法错误。上代码:
String insertSQL = "insert into " + tablename + "(date, paraname, paravalue) values(?, ?, ?)";
PreparedStatement pstm = conn.prepareStatement(insertSQL);
int rand = 1000000000 + new Random().nextInt(1000000000);
java.sql.Date adate = new java.sql.Date(System.currentTimeMillis() - rand);
pstm.setDate(1, adate);
pstm.setString(2, points.get(0));
pstm.setFloat(3, 1.0F);
pstm.execute(insertSQL);
每次都报告语法错误:
check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?, ?)' at line 1
几经查找,最后才发现,调用格式错误!!应该直接调用execute();不带参数!!!耗费了半天的时间,冤啊!!
所以,记录在案!