This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException" Watch "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException" New topic
Author

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

Li Jenny
Ranch Hand

Joined: Apr 19, 2010
Posts: 57
i would like to retrieve a field which is defined the datatype 'varchar(45)'

when i enter number to retrieve that field as below:

select * from ATable where field='123';

it causes sql syntax error
why?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Your query is wrongly formatted. Print the final query and execute the same on the MySQL query analyzer.
And this is not the right section to ask JDBC question.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Li Jenny
Ranch Hand

Joined: Apr 19, 2010
Posts: 57
replied
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Li Jenny wrote:when i enter number to retrieve that field as below:

select * from ATable where field='123';

it causes sql syntax error
why?

This SQL is syntactically correct. The problem is the SQL query which gets formatted when you assign the parameter in JDBC code. I repeat, check the resultant query from JDBC code. The problem is there.
 
 
subject: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException