• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MySQLSyntaxErrorException

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to refer MySQL manual for the right syntax for the statement. Hope this helps
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell
Thanks a ton! I have inserted "Values" and it worked !

Thank you Vijitha, for your help !
 
please buy this thing and then I get a fat cut of the action:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic