我该如何修复java.sql.BatchUpdateException?

时间:2014-04-22 07:14:52

标签: java mysql sql prepared-statement batch-updates

我编写了一个用jdbc连接到mysql db的java程序。它将记录插入mysql。 sql是这样的:

 INSERT   INTO my_schema.my_table VALUES ('AMERICAN', '97', '1995-08-28 00:00:00', '10', '1995-08-28 00:00:00', '10', 'United States Dollar', 'USD', '$', '2', 'Y', 'Y', '1995-08-28 00:00:00', '_6064530F8DBAB938E040007F010015E3' );

但它给出了这个错误:

e = (java.sql.BatchUpdateException) 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 '('AMERICAN', '40', '1995-08-28 00:00:00', '10', '1995-08-28 00:00:00', '10', 'Ja' at line 1

但奇怪的是:我手动插入它没有错误。

提前感谢,

1 个答案:

答案 0 :(得分:1)

这很奇怪,但它有效:

我只删除了最后一个字符分号,它的工作原理为:

我的意思是我改变了这个:

INSERT   INTO my_schema.my_table VALUES ('AMERICAN', '97', '1995-08-28 00:00:00', '10', '1995-08-28 00:00:00', '10', 'United States Dollar', 'USD', '$', '2', 'Y', 'Y', '1995-08-28 00:00:00', '_6064530F8DBAB938E040007F010015E3' );

到此:

INSERT   INTO my_schema.my_table VALUES ('AMERICAN', '97', '1995-08-28 00:00:00', '10', '1995-08-28 00:00:00', '10', 'United States Dollar', 'USD', '$', '2', 'Y', 'Y', '1995-08-28 00:00:00', '_6064530F8DBAB938E040007F010015E3' )