• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error - prepared statement

 
raj kiyare
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
raj kiyare
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20971
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic