尝试从Java应用程序中插入此dateTime有什么问题?
对于此Java代码:尝试从Java应用程序中插入此dateTime有什么问题?,java,mysql,datetime,jdbc,Java,Mysql,Datetime,Jdbc,对于此Java代码: stmt.addBatch( "INSERT INTO Bills (BillDateTime, Table, Item, NoAttended, Service, Payment, Total) " + "VALUES('" + billDateTime + "', " + Integer.parseInt(createTableNumberOutput.toString()) + ", '" + nul
stmt.addBatch(
"INSERT INTO Bills (BillDateTime, Table, Item, NoAttended, Service, Payment, Total) " +
"VALUES('" + billDateTime + "', " + Integer.parseInt(createTableNumberOutput.toString()) + ", '" + null + "', '"
+ Integer.parseInt(createGuestNumberOutput.toString()) + "', " + "5" + ", '" +
createPaymentTypeOutput.toString() + "', '" + "')");
我得到以下错误:
java.sql.BatchUpdateException: 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 'Table, Item, NoAttended, Service, Payment, Total) VALUES('2012-03-26 11:15:8', 1' at line 1
这个问题对我来说并不明显,因为MySql需要dateTime的格式'YYYY-MM-DD HH:MM:SS',我有,对吗?表在MySql中。在其周围使用反勾号
如下图所示:
stmt.addBatch("INSERT INTO Bills (BillDateTime,`Table`, Item,NoAttended,Service,Payment,Total..........")
表在mysql中。在其周围使用反勾号
如下图所示:
stmt.addBatch("INSERT INTO Bills (BillDateTime,`Table`, Item,NoAttended,Service,Payment,Total..........")
即使修复了保留关键字表的问题,它仍然不起作用。您正在尝试在日期字段中插入date.toString。连接时,toString将调用所有非字符串对象
相反,您应该使用并调用stm.setDate。。。更加熟悉准备好的陈述,因为这通常是更好的方式。它还有addBatch,它的工作方式稍有不同-您可以设置所有参数,然后添加,然后再次设置。即使修复保留关键字表问题,它仍然无法工作。您正在尝试在日期字段中插入date.toString。连接时,toString将调用所有非字符串对象 相反,您应该使用并调用stm.setDate。。。更加熟悉准备好的陈述,因为这通常是更好的方式。它还有addBatch,它的工作方式稍有不同——设置所有参数,然后添加,然后再次设置