It's not a secret anymore!*
The moose likes JDBC and the fly likes MySQLSyntaxErrorException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQLSyntaxErrorException" Watch "MySQLSyntaxErrorException" New topic
Author

MySQLSyntaxErrorException

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi All
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.

JSP:


Servlet:


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?


Thanks & Regards
Swapna Gouri
I "try", I "catch" and "finally" WIN !!!
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

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?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi Vijitha
Thanks for the rectification! I have rectified the program but still getting the same error.
Have any idea what could have been the problem?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Can you post your new(rectified) SQL statement with relative code & stack trace?
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Here's the rectified code Vijitha


And here's the stack trace:



Will be very grateful to you if you can help me in solving this problem...
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Any help guys? Will be very much thankful and grateful if any one can help me in solving this problem.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

You will have to refer MySQL manual for the right syntax for the statement. Hope this helps
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
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.
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi Campbell
Thanks a ton! I have inserted "Values" and it worked !

Thank you Vijitha, for your help !
 
Consider Paul's rocket mass heater.
 
subject: MySQLSyntaxErrorException
 
Similar Threads
JSP Help Regarding the Radio Button
I M NOT ABLE TO DEFINE VARIABLES IN JSP.
Getting NullPointerException
problem in jsp !!!
please any one cleare my error