怎么我老是连接不上数据库啊!急!

tanjiaqi 2002-05-30 09:53:29
源文件:
<%@page language="java" import="java.sql.*"%>
<%@page import="java.text.*"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<html>
<head>
<title>DateBase Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=null;
con=DriverManager.getConnection("jdbc:odbc:address","","");
Statement stmt=con.createStatement();
ResultSet rs;
rs=stmt.executeQuery("select * from address");
%>
<%=rs.getString("name")%>

</body>
</html>
运行结果:
Error: 500
Location: /db.jsp
Internal Servlet Error:

javax.servlet.ServletException: [Microsoft][ODBC ???? ???] ???????
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:455)
at db_1._jspService(db_1.java:90)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:500)
at org.apache.tomcat.core.Handler.service(Handler.java:223)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:448)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:911)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:824)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:152)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:438)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:505)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.sql.SQLException: [Microsoft][ODBC ???? ???] ???????
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3266)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5377)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:320)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:376)
at db_1._jspService(db_1.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:500)
at org.apache.tomcat.core.Handler.service(Handler.java:223)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:448)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:911)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:824)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:152)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:438)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:505)
at java.lang.Thread.run(Thread.java:484)


...全文
90 点赞 收藏 9
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zijianyi 2002-05-31
哦,有道理,他说没有连接上数据库,我就没仔细看代码.........还是兄细心!
回复
baby_zhx 2002-05-31
呵呵,应该是数据源的问题,你在看看控制面板——管理工具——数据源中的DSN的配置,检查一下,(编程就是要细心),或者是你把
<%=rs.getString("name")%>
换成
<%rs.next();
rs.getString(1);

%>
试一下
回复
xycleo 2002-05-31
估计楼上的说得对
回复
zjgj 2002-05-31
我是初学者前几天我也碰到这个问题位大虾帮我解决的,我不知道你是不是与我碰到同样的问题,我出错是因为我在选ODBC时选取了Driver do microsoft Access
就怎样也连不上,后来选了Miscrosoft Access Driver就可以了。我只是想帮忙,可能我太菜。你应该不会犯我这种低级错误吧。
回复
javagoo 2002-05-31
代码中少一段代码:rs.next();
<%
rs.next();
%>
<%=rs.getString("name")%>
<%
rs.close();
stmt.close();
con.close();
%>
试试看
回复
weidegong 2002-05-30
<%=rs.getString("name")%>

前边至少加一句:rs.next()吧?

那一堆错误信息关键部分还是乱码,也不知道说什么
回复
tanjiaqi 2002-05-30
我用的是access数据库啊
回复
zijianyi 2002-05-30
你用的什么数据库?

<%@ page language="java" import="java.sql.*" contentType="text/html;charset=gb2312"%>
<%//@ page errorPage="../err.jsp"%>
<%
java.sql.Connection Conn;
java.sql.Statement Stmt;
java.sql.ResultSet Rst;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Conn=DriverManager.getConnection("jdbc:odbc:数据源","用户名","密码");
Stmt=Conn.createStatement();
%>
回复
tanjiaqi 2002-05-30
由于是测试
写得简单了一点
可是为什么数据就是不能显示呢?
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告