关于数据库的简单问题,大虾帮我啊!
程序:
<html>
<body>
<%@ page contentType= "test/html;charset=GB2312 " %>
<%@ page import= "java.sql.* "%>
<%
Connection con;
Statement sql;
ResultSet rs;
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
con=DriverManager.getConnection( "jdbc:odbc:sun ", "sa ", " ");
sql=con.createStatement();
rs=sql.executeQuery( "SELECT * FROM Students ");
while(rs.next()){
out.print(rs.getString(1));
out.print(rs.getString(2));
}
con.close();
%>
</body>
</html>
报错:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /hh.jsp at line 16
13:
14: con=DriverManager.getConnection( "jdbc:odbc:sun ", "sa ", " ");
15: sql=con.createStatement();
16: rs=sql.executeQuery( "SELECT * FROM Students ");
17: while(rs.next()){
18: out.print(rs.getString(1));
19: out.print(rs.getString(2));
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]对象名 'Students ' 无效。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.hh_jsp._jspService(hh_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]对象名 'Students ' 无效。
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
org.apache.jsp.hh_jsp._jspService(hh_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
已经弄了很长时间了,各位帮帮忙啊!
[解决办法]
'Students ' 这个表 存在马
[解决办法]
检查一下大小写,就是那个表明的大小写!!!!
你是不是用的sql server数据库?
select * from students试试
[解决办法]
Connection con;
Statement sql;
ResultSet rs;
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
try{
con=DriverManager.getConnection( "jdbc:odbc:sun ", "sa ", " ");
sql=con.createStatement();
rs=sql.executeQuery( "SELECT * FROM Students ");
while(rs.next()){
out.print(rs.getString(1));
out.print(rs.getString(2));
}
catch(SQLException e){}
finally{
if(rs!=null)rs.close();
if(sql!=null)sql.close();
if(conn!=null)conn.close();
}
[解决办法]
你数据库服务器开了没?!
[解决办法]
如果表名正确的话,肯定是ODBC里面配的数据库错了
看看你选的数据库里面有没有students这个表
[解决办法]
应该是大小写的问题
[解决办法]
数据库名是什么?
[解决办法]
应该是ODBC配置不正确
[解决办法]
SQL 2000 大小写都是可以的..
我认为就是你的表没有在数据库里.
我建议你先把表名换成一个字母.
[解决办法]
怀疑两点:一是上面的老兄们说的,表的问题。
二是:con=DriverManager.getConnection( "jdbc:odbc:sun ", "sa ", " ");这个连接是不是有问题
[解决办法]
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]对象名 'Students ' 无效。
很明显的,数据库表的原因,找不到这个表,不是连接原因,
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html