This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQL syntax error, can anyone help?