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 You have an error in your SQL syntax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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: 4240
    
    7

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: 4240
    
    7

You're welcome!
 
 
subject: You have an error in your SQL syntax
 
Similar Threads
How to read and write for Image and PDF files
How to ask for user input twice?
Prepared Statement problem in my servlet's data manager
I/O question
java uses or overrides a deprecated API.