Meaningless Drivel is fun!*
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
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: 18541
    
    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: 1615
    
  13

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: http://aspose.com/file-tools
 
subject: Insert query from java program
 
Similar Threads
JSP: Unable to connect to mysql in local drive [Solved]
Special characters not appearing on JSP page
JDBC Newbie
Retrive a single data from database and display that in jsp text box.
JSP DataBase Connection