File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQLSyntaxErrorException

 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your new(rectified) SQL statement with relative code & stack trace?
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help guys? Will be very much thankful and grateful if any one can help me in solving this problem.
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to refer MySQL manual for the right syntax for the statement. Hope this helps
 
Paul Campbell
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell
Thanks a ton! I have inserted "Values" and it worked !

Thank you Vijitha, for your help !
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic