I have written a program using Servlets and JSP where am trying to enter data into database(MySQL) using the JSP page. But I'm getting a MySQLSyntaxErrorException after submitting the data from the JSP page. Here are the servlet and JSP programs...
Using the following versions: MySQL 5.0, Tomcat 6, MySQL Connector-J 5.1.7, Eclipse IDE.
Error on Tomcat console:
My database entries seem to be perfect and I'm not able to find the problem with my syntax. Can any one help me out to trace out the problem?
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error inyour SQL syntax; check the manual that corresponds to your MySQL server versionfor the right syntax to use near 'ComponentDetails('asjdhk','akahdsfkja',3947,'sjhfka','kadhf',3947319,'1234-12-12' at line 1
This says the error.
Insert statements start with INSERT INTO tablename (......) VALUES (....)
But you have two identifiers after INSERT INTO.., are both the table name or what?
Originally posted by Swapna Gouri Kalanidhi:
Here's the rectified code Vijitha
Will be very grateful to you if you can help me in solving this problem...
There are two forms for a SQL insert statement.
The first form doesn't specify the column names where the data will be inserted, only their values (you insert all the columns in order):
This seems to be the format of your statement. However, you're still not including the VALUES clause before your column values. Add the VALUES clause before your parentheses and make sure you're have all your columns specified in order.
The second form specifies both the column names and the values to be inserted:
Use this one if you're not including all the columns... and don't forget your VALUES clause.