This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes Insert query from java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert query from java program" Watch "Insert query from java program" New topic
Author

Insert query from java program

duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64

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
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

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

Joined: Mar 01, 2009
Posts: 1786
    
  16

Think about your column names in the INSERT:

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

And use a PreparedStatement.


No more Blub for me, thank you, Vicar.
 
Don't get me started about those stupid light bulbs.
 
subject: Insert query from java program