1

I write a java program that connect to mysql db with jdbc.It inserts records to mysql. The sql is this:

 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' );

But it gives this error:

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

But the weird thing is : I insert it manually without error.

thanks in advance,

4
  • do you have a auto incremented primary key in the table ? Commented Apr 22, 2014 at 7:25
  • no I do not have primary key Commented Apr 22, 2014 at 7:26
  • hmm the error looks like due to having some quote in the string somewhere. Commented Apr 22, 2014 at 7:28
  • @ErsinGülbahar: Can you post java code that creates batch statements and how values are set in the sql statement? Commented Apr 22, 2014 at 8:01

1 Answer 1

2

It is weird but it works:

I just remove the last character semicolon , and it works:

I mean I change this:

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' );

to this:

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' )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.