File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Insert query from java program" Watch "Insert query from java program" New topic

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

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Mar 01, 2009
Posts: 2292

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.
I agree. Here's the link:
subject: Insert query from java program
It's not a secret anymore!