Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert query from java program

 
duhit Choudhary
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i have made this program to fire a query from the java program and hence to insert rows in the database. But unfortunately on execution i am getting an exception as :-
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 '-Type, Kind, Location, Artist) VALUES ('null', 'null', 'null','null')' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) on line 73.... please help and tell where am i wrong!!!
 
Paul Clapham
Sheriff
Pie
Posts: 20763
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a good chance that you've got the wrong number of quotes, or apostrophes, or that you have them in the wrong place. I suggest dropping the idea of creating an insert query by concatenating strings -- this situation is only one reason why it's a bad idea to do that. Use a PreparedStatement instead.

Also, it looks like the variables you're trying to put into the query (TrackTypes and so on) are all null. Did you expect that to be the case? If not, you might want to find out why that is happening. But use the PreparedStatement regardless.

 
chris webster
Bartender
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about your column names in the INSERT:

INSERT INTO track( Track-Type, ....

And use a PreparedStatement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic