主题:连接数据库出错
错误提示:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 6 in the jsp file: /sqlserver/jodbc/example1-1.jsp
Generated servlet error:
rs cannot be resolved
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
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.*"%>
<html>
<body>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception E) {
out.println("Unable to load driver.");
}
try{
Connection con;
Statement sql;
ResultSet rs;
String url="jdbc:odbc:jspexample";
String user="sa";
String password="*****";
con=DriverManager.getConnection(url,user,password);
sql=con.createStatement();
rs=sql.executeQuery("select * from students");
out.print("<table border=1>");
while(rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getInt("数学成绩")+"</td>");
out.print("<td>"+rs.getInt("英语成绩")+"</td>");
out.print("<td>"+rs.getInt("物理成绩")+"</td>");
out.print("</tr>");
}
out.print("</table>");
}
catch(Exception e){out.print(e);}
out.println("数据库操作成功");
rs.close();
%>
</body>
</html>
哪错了?????
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 6 in the jsp file: /sqlserver/jodbc/example1-1.jsp
Generated servlet error:
rs cannot be resolved
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
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.*"%>
<html>
<body>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception E) {
out.println("Unable to load driver.");
}
try{
Connection con;
Statement sql;
ResultSet rs;
String url="jdbc:odbc:jspexample";
String user="sa";
String password="*****";
con=DriverManager.getConnection(url,user,password);
sql=con.createStatement();
rs=sql.executeQuery("select * from students");
out.print("<table border=1>");
while(rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getInt("数学成绩")+"</td>");
out.print("<td>"+rs.getInt("英语成绩")+"</td>");
out.print("<td>"+rs.getInt("物理成绩")+"</td>");
out.print("</tr>");
}
out.print("</table>");
}
catch(Exception e){out.print(e);}
out.println("数据库操作成功");
rs.close();
%>
</body>
</html>
哪错了?????