JSP连接Oracle报错问题
错误信息:exceptionorg.apache.jasper.JasperException:UnabletocompileclassforJSPAnerroroccu...
错误信息:
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 22 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
An error occurred at line: 23 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
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
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 22 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
An error occurred at line: 23 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
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)
源代码:
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<html>
<head>
<title>Ora</title>
</head>
<body>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:abc","LIJIE","abc");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM USER");
}
catch(Exception e){}
%>
<%=rs.getString(1)%>;
<%=rs.getString(2)%>;
后略.
请问是什么问题?我应该如何导出表中内容?
rs.getString("NAME")也不行...
把对象都定义到外面了,新的错误是
org.apache.jasper.JasperException: Exception in JSP: /Ora.jsp:29
就是<%=rs.getString(1)%> 这行...
请问是什么问题 展开
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 22 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
An error occurred at line: 23 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
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
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 22 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
An error occurred at line: 23 in the jsp file: /Ora.jsp
Generated servlet error:
rs cannot be resolved
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
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)
源代码:
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<html>
<head>
<title>Ora</title>
</head>
<body>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:abc","LIJIE","abc");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM USER");
}
catch(Exception e){}
%>
<%=rs.getString(1)%>;
<%=rs.getString(2)%>;
后略.
请问是什么问题?我应该如何导出表中内容?
rs.getString("NAME")也不行...
把对象都定义到外面了,新的错误是
org.apache.jasper.JasperException: Exception in JSP: /Ora.jsp:29
就是<%=rs.getString(1)%> 这行...
请问是什么问题 展开
2个回答
展开全部
同意楼上的看法
但是不用两个try
这样就可以了
<% Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:abc", "LIJIE", "abc");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM USER");
while (rs.next()){ %>
<%=rs.getString(1)%>
<%
out.println(rs.getString(1));
}
} catch (ClassNotFoundException ex) {
} catch (SQLException e) {
e.printStackTrace();
}
%>
看看怎么样
你原来都没有异常处理 没有异常处理是不可以的
但是不用两个try
这样就可以了
<% Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:abc", "LIJIE", "abc");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM USER");
while (rs.next()){ %>
<%=rs.getString(1)%>
<%
out.println(rs.getString(1));
}
} catch (ClassNotFoundException ex) {
} catch (SQLException e) {
e.printStackTrace();
}
%>
看看怎么样
你原来都没有异常处理 没有异常处理是不可以的
展开全部
<%=rs.getString(1)%> 是把内容输出到JSP页面上,
换个写法试试<%out.println(rs.getString(1));%>
没有找到对象rs,rs声明在try里面,外面调用可能找不到这个对象
重新写了下,运行试试
<% Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:abc", "LIJIE", "abc");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM USER");
} catch (ClassNotFoundException ex) {
} catch (SQLException e) {
e.printStackTrace();
}
%>
<% try {
while (rs.next()) {%>
<%=rs.getString(1)%>
<%}
} catch (SQLException e) {
e.printStackTrace();
}
%>
换个写法试试<%out.println(rs.getString(1));%>
没有找到对象rs,rs声明在try里面,外面调用可能找不到这个对象
重新写了下,运行试试
<% Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:abc", "LIJIE", "abc");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM USER");
} catch (ClassNotFoundException ex) {
} catch (SQLException e) {
e.printStackTrace();
}
%>
<% try {
while (rs.next()) {%>
<%=rs.getString(1)%>
<%}
} catch (SQLException e) {
e.printStackTrace();
}
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询