• 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

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: 41860
908
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: 41860
908
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.
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic