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 You have an error in your SQL syntax 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 "You have an error in your SQL syntax" Watch "You have an error in your SQL syntax" New topic
Author

You have an error in your SQL syntax

Daniel Victor
Greenhorn

Joined: Mar 04, 2013
Posts: 2
I am a beginner and I tried to do a program involving JDBC involving mySQL.
The program displays a menu that lets the user to choose an option. I used a switch and from there, I call the methods.

I haven't written the code for the delete method yet.

display method


insert method

When I run the insert method, it errs saying, Error: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 ''Dan','Vuyyur',7845)' at line 1
Someone please tell me what I have done wrong. Is it like the mismatch in the datatypes? The datatype of the field in the mySQL table and the int declared here in Java?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4377
    
    8

Hi Daniel. Welcome to the Ranch.

I think you've got your INSERT statement syntax wrong. Try:
(obviously change it to whatever your actual column names are).

Are you sure you want to store phone numbers using a numeric type? A string would be much more common. You can have numbers that start with a 0 which will be removed in a number. You also might want spaces or other formatting, and possible international numbers (using +). And you never need to carry out arithmetic on a phone number.

Daniel Victor
Greenhorn

Joined: Mar 04, 2013
Posts: 2
Thank you so much. I didn't check the query. As I thought it is something more complicated. Thank you, sir. And I was just practicing, later on, I will take the phone as a String.
And I couldn't figure out how to reply to you. @Matthew Brown.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4377
    
    8

You're welcome!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: You have an error in your SQL syntax