
Dear Sir,
I am again struck in my project.. i want to display data from oracle database but i get this error when i run the jsp file in tomcat, I post my code below.. kindly let me know what i am wrong!! kindly help me in this.
out.jsp
<%@ page session="false"%>
<%@ page import="java.io.*" import="java.sql.*"%>
<%try {
Connection con=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@//172.25.50.247:1521/knits", "ADMIN", "ADMIN");
ps=con.prepareStatement("select * from departments");
ResultSet rs= ps.executeQuery();
while(rs.next())
{
out.println(rs.getInt(name));
out.println(rs.getString(id));
} } catch(Exception e) {}
rs.close();
ps.close();
con.close(); %>
Error from apache tomcat type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 9 in the jsp file: /jsp/test/form.jsp
Duplicate local variable con
6: Class.forName("oracle.jdbc.driver.OracleDriver");
7:
8: Connection
9: con=DriverManager.getConnection("jdbc:oracle:thin:@//172.25.50.247:1521/knits", "ADMIN", "ADMIN");
10:
11: ps=con.prepareStatement("select * from departments");
12: ResultSet rs= ps.executeQuery();
An error occurred at line: 11 in the jsp file: /jsp/test/form.jsp
ps cannot be resolved to a variable
8: Connection
9: con=DriverManager.getConnection("jdbc:oracle:thin:@//172.25.50.247:1521/knits", "ADMIN", "ADMIN");
10:
11: ps=con.prepareStatement("select * from departments");
12: ResultSet rs= ps.executeQuery();
13: while(rs.next())
14: {
An error occurred at line: 12 in the jsp file: /jsp/test/form.jsp
ps cannot be resolved
9: con=DriverManager.getConnection("jdbc:oracle:thin:@//172.25.50.247:1521/knits", "ADMIN", "ADMIN");
10:
11: ps=con.prepareStatement("select * from departments");
12: ResultSet rs= ps.executeQuery();
13: while(rs.next())
14: {
15: out.println(rs.getInt(name));
An error occurred at line: 15 in the jsp file: /jsp/test/form.jsp
name cannot be resolved to a variable
12: ResultSet rs= ps.executeQuery();
13: while(rs.next())
14: {
15: out.println(rs.getInt(name));
16: out.println(rs.getString(id));
17: } } catch(Exception e) {}
18: rs.close();
An error occurred at line: 16 in the jsp file: /jsp/test/form.jsp
id cannot be resolved to a variable
13: while(rs.next())
14: {
15: out.println(rs.getInt(name));
16: out.println(rs.getString(id));
17: } } catch(Exception e) {}
18: rs.close();
19: ps.close();
An error occurred at line: 18 in the jsp file: /jsp/test/form.jsp
rs cannot be resolved
15: out.println(rs.getInt(name));
16: out.println(rs.getString(id));
17: } } catch(Exception e) {}
18: rs.close();
19: ps.close();
20: con.close(); %>
An error occurred at line: 19 in the jsp file: /jsp/test/form.jsp
ps cannot be resolved
16: out.println(rs.getString(id));
17: } } catch(Exception e) {}
18: rs.close();
19: ps.close();
20: con.close(); %>
An error occurred at line: 20 in the jsp file: /jsp/test/form.jsp
con cannot be resolved
17: } } catch(Exception e) {}
18: rs.close();
19: ps.close();
20: con.close(); %>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.