File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQL syntax error, can anyone help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL syntax error, can anyone help?" Watch "SQL syntax error, can anyone help?" New topic
Author

SQL syntax error, can anyone help?

Eric Howell
Ranch Hand

Joined: Nov 26, 2000
Posts: 63
I have the following to insert 3 strings into a MySQL database from a JavaBean.
The equivelent code works when I insert directly into the database but when I use JDBC I get the error :
" JDBC error: java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near ''urlString','FOX BROADCASTING COMPANY','...etc
I wonder if someone can spot what is wrong?
Thanks in advance

and later on I have the usual


Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
can you post the actual resulting string from queryString?
it seems like a jdbc error, not a sql error. are you sure it's set up right?

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
sorry, that's cr*p - but i can't get back to my post to edit it. just post the actual SQL string you send, rather than the code that compiled it.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
sorry i'm doing it again - try dropping the ; at the end of the statement.
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
Originally posted by Eric Howell:

[ CODE ]
String queryString = "INSERT INTO "+dbTable+ "VALUES('"+urlString+"','"+titleString+"','"+descriptionString+"');" ;
[ /CODE ]

Also, there should be a space before the word VALUES as in
String queryString = "INSERT INTO "+dbTable+ " VALUES ('"+urlString+"','"+titleString+"','"+descriptionString+"')" ;
and of course as mentioned by Adam, drop the ';' after '"+descriptionString+"'
Eric Howell
Ranch Hand

Joined: Nov 26, 2000
Posts: 63
Thanks lads. It was infact the space before the INSERT that did the trick.
Thanks for the help again
Cheers
Eric
 
 
subject: SQL syntax error, can anyone help?