Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

javax.servlet. ServletException error

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following code but cant seem to trace where the error is coming from. Thank you for your help.

String userID= (String) session.getAttribute("userID");
String query1 = "SELECT (A.Leave - sum(B.Duration)) AS BALANCE_LEAVE FROM users A, leave B WHERE A.userID=B.userID AND A.userID = '" + userID + "'";
rst1 = stm1.executeQuery(query1);


The error is
javax.servlet.ServletException: 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 'leave B WHERE A.userID=B.userID AND A.userID = 'staff'' at line 1
 
author & internet detective
Posts: 41578
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vanan,
If you copy/paste the SQL into the database command line, what message do you get? Is it clearer?
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help Jeanne Boyarsky but i'm unsure how to carry out what you said. I'm using mysql5 and tomcat 4. Is there anything wrong in the sql syntax.
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Managed to solve the problem.

String userID= (String) session.getAttribute("userID");
String query1 = "SELECT (A.Leave - sum(B.Duration)) AS BALANCE_LEAVE FROM users A, leave B WHERE A.userID=B.userID AND A.userID = '" + userID + "'";
rst1 = stm1.executeQuery(query1);


A.Leave and leave B should not be the same. I changed my table name to leavetest B and it worked.


Thank you
 
Jeanne Boyarsky
author & internet detective
Posts: 41578
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great. Thanks for posting the solution.
 
Tell me how it all turns out. Here is a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic