• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.servlet. ServletException error

 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great. Thanks for posting the solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic