• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL syntax error, can anyone help?

 
Eric Howell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i'm doing it again - try dropping the ; at the end of the statement.
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks lads. It was infact the space before the INSERT that did the trick.
Thanks for the help again
Cheers
Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic