Forums Register Login

error - prepared statement

+Pie Number of slices to send: Send
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




+Pie Number of slices to send: Send
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().
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.?
+Pie Number of slices to send: Send
 

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)
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
thank you for the reply.
Paper jam tastes about as you would expect. Try some on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2193 times.
Similar Threads
JSP with Jdbc
The max input fields for servlet can handle
please any one cleare my error
javax.servlet.ServletException: Cannot find bean employerSearchForm in any scope
Display Java Method Result in JSP
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:49:47.