aspose file tools*
The moose likes JDBC and the fly likes error - prepared statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "error - prepared statement" Watch "error - prepared statement" New topic
Author

error - prepared statement

raj kiyare
Greenhorn

Joined: Apr 21, 2011
Posts: 16
Hi,
I'm getting the following error while using Prepared statement. Could some one tell me where i'm going wrong.

error:


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /DBTest.jsp:31

28: res = "Fail";
29: else
30: res = "Pass";
31: ps.setInt(1,no);
32: ps.setString(2,name);
33: ps.setInt(3,total);
34: ps.setFloat(4,avg);


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:395)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause

java.lang.NullPointerException
org.apache.jsp.DBTest_jsp._jspService(DBTest_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


files i'm using

input.html



DBTest.jsp




Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Can you check your output and error files? My guess is that ps is null, which means you must have had an exception. You log that to System.err, as that's the default for e.printStackTrace().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
raj kiyare
Greenhorn

Joined: Apr 21, 2011
Posts: 16
sorry for replying late. was not online for few days. anyway.

i tried making the following changes.

i just added try catch block like this



now i'm not getting error. and it is calculating avg also.
I'm a new to JSP. i read that you need not do exception handling in JSP. it is automatic. i mean it will automatically have exception handling in JSP equivalent servelt.
So first is it compulsory to do in exception handling in JSP also.
second. Though it is not giving any errors . it is not inserting the data in table can you say why?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

raj kiyare wrote:So first is it compulsory to do in exception handling in JSP also.

Well, ideally you shouldn't need to do any exception handling in the JSP because you shouldn't have any Java code in the JSP. All that should be in a servlet.
raj kiyare
Greenhorn

Joined: Apr 21, 2011
Posts: 16
Matthew Brown wrote:
raj kiyare wrote:So first is it compulsory to do in exception handling in JSP also.

Well, ideally you shouldn't need to do any exception handling in the JSP because you shouldn't have any Java code in the JSP. All that should be in a servlet.



So do you mean when I write java scriplets i need to write exception handling explicitly.?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

raj kiyare wrote:


So do you mean when I write java scriplets i need to write exception handling explicitly.?


He means don't use scriptlets. Don't have any java code on your jsp page, period.

I know you are just testing your db connection, but all DB Stuff should be handled in a servlet. ( = a java class file)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18988
    
    8

raj kiyare wrote:So do you mean when I write java scriplets i need to write exception handling explicitly.?


No. If you're writing Java code then you need to take care of exception handling, especially for JDBC code. And just because you put that Java code into a scriptlet, that doesn't magically make the exception handling requirement go away.
raj kiyare
Greenhorn

Joined: Apr 21, 2011
Posts: 16
thank you for the reply.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: error - prepared statement