|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 9
|
Problem with JSP File
Hello,
I am having a problem with the code posted below. When I try to run the jsp file in firefox I get this error: org.apache.jasper.JasperException: An exception occurred processing JSP page /JSP9.jsp at line 29 26: 27: String name=request.getParameter("name"); 28: //stmt.executeUpdate("insert into Rot(name) value('"+name+"')"); 29: rst=stmt.executeQuery("select name from Rot"); 30: 31: 32: %> Any help would be appreciated. Rot is the name of a test database on my system created by MySQL. I am also running Tomcat on my computer. <%@ page language="java" import="java.sql.*"%> <% String driver = "org.gjt.mm.mysql.Driver"; Class.forName(driver).newInstance(); Connection con=null; ResultSet rst=null; Statement stmt=null; try{ String url="jdbc:mysql://localhost/David?user=deepak&password=deepak"; con=DriverManager.getConnection(url); stmt=con.createStatement(); }catch(Exception e){ System.out.println(e.getMessage()); } if(request.getParameter("action") == null){ String name=request.getParameter("name"); //stmt.executeUpdate("insert into Rot(name) value('"+name+"')"); rst=stmt.executeQuery("select name from Rot"); %> <html> <body> <center><h2>Books List</h2> <table border="1" cellspacing="0" cellpadding="0"> <tr><td><b>Id</b></td><td><b>Name<b></td></tr> <% int no=1; while(rst.next()){ %> <tr><td><%=no%></td> <td><%=rst.getString("name")%></td></tr> <% no++; } rst.close(); stmt.close(); con.close(); %> </table> </center> </body> </html> <%}else{%> return 1; <%}%> |
|
|
|
|
|
#2 |
|
SitePoint Enthusiast
![]() Join Date: Jul 2006
Location: UK
Posts: 73
|
Move your catch block so you get the exception displayed in the browser... This will help you see what the problem is...
I commented this line out too for now... "if(request.getParameter("action") == null){" Code:
<%@ page language="java" import="java.sql.*"%>
<%
String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try{
String url="jdbc:mysql://localhost/David?user=deepak&password=deepak";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
//if(request.getParameter("action") == null){
String name=request.getParameter("name");
//stmt.executeUpdate("insert into Rot(name) value('"+name+"')");
rst=stmt.executeQuery("select name from Rot");
catch(Exception e){
System.out.println(e.getMessage());
}
%>
|
|
|
|
|
|
#3 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 9
|
Thanks for the help zink but I still can't seem to get this one. I will post the changes to the code I have made
%@ page language="java" import="java.sql.*"%> <%@page contentType="text/html" %> <% String driver = "org.gjt.mm.mysql.Driver"; Class.forName(driver).newInstance(); Connection con=null; ResultSet rst=null; Statement stmt=null; try{ String url="jdbc:mysql://localhost/David?user=deepak&password=deepak"; con=DriverManager.getConnection(url); stmt=con.createStatement(); String name=request.getParameter("name"); stmt.executeUpdate("insert into Rot(name) values('"+name+"')"); rst=stmt.executeQuery("select name from Rot"); } catch(Exception e){ System.out.println(e.getMessage()); } %> <html> <body> <%while(rst.next()){%> <p><%=rst.getString("name")%></p> <%}%> </body> </html> |
|
|
|
|
|
#4 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2002
Location: Paris
Posts: 1,029
|
Code:
}
catch(Exception e){
System.out.println(e.getMessage());
}
Code:
StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); out.print(sw.getBuffer().toString()); |
|
|
|
|
|
#5 |
|
SitePoint Member
Join Date: Oct 2009
Posts: 20
|
You should be SELECTING from a table not a database.
but yeh, you should def be throwing a runtime exception to see the actual exception. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 18:44.









Linear Mode
