This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

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: 2205
    
  22

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Insert query from java program
 
It's not a secret anymore!