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)%> 这行...
请问是什么问题
展开
 我来答
yys22222
2007-04-14
知道答主
回答量:12
采纳率:0%
帮助的人:0
展开全部
同意楼上的看法
但是不用两个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();
}
%>
看看怎么样
你原来都没有异常处理 没有异常处理是不可以的
sky84110
2007-04-03 · 超过14用户采纳过TA的回答
知道答主
回答量:62
采纳率:0%
帮助的人:46.4万
展开全部
<%=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();
}
%>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式