wood burning stoves 2.0*
The moose likes JDBC and the fly likes javax.servlet. ServletException error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "javax.servlet. ServletException error" Watch "javax.servlet. ServletException error" New topic
Author

javax.servlet. ServletException error

vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Vanan,
If you copy/paste the SQL into the database command line, what message do you get? Is it clearer?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
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

Joined: Jun 02, 2006
Posts: 95
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Great. Thanks for posting the solution.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: javax.servlet. ServletException error
 
Similar Threads
SQL subquery performs too slowly
Unsure how to do subtraction using joined table values
Hibernate mapping
Native SQL for fetching relationship fields
Liferay Query/ dynamic query/ custom SQL help