JDBC-ODBC的问题

hjwb2003 2007-05-09 03:42:58
数据库是access文件,建立了ODBC,程序如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="conn" scope="page" class="conn.openDB"/>
<%@ include file="System/SysFunction.jsp" %>
<%@ include file="System/FkFunction.jsp" %>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
<META HTTP-EQUIV="Pragma" CONTENT="No-Cache">
<SCRIPT LANGUAGE="JavaScript" SRC="System/Query.js"></SCRIPT>
<TITLE></TITLE>
<LINK Rel="Stylesheet" Type="text/css" Href="../System/Query.css">
</HEAD>
<style type="text/css">
<!--
.style1 {
font-size: 20px;
font-weight: bold;
}
-->
</style>

<body>
<div align="center" class="style1">JSP连接Access数据库</div>
<br>
<hr>
<p>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //载入驱动程序类别
Connection con = DriverManager.getConnection("jdbc:odbc:db"); //建立数据库链接,jspdata为ODBC数据源名称
//建立Statement对象
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
int cc=0;


ResultSet rs = stmt.executeQuery("select * from tb1"); //建立ResultSet(结果集)对象,并执行SQL语句
//存储数据%>
</p>
<p align="center">NUMB1数据表中记录如下</p>
<table width="640" border="1" align="center" bordercolor="#7188e0">


<tr bgcolor="d1d1ff">
<th>NBH</th>
<th>XM</th>
<th>DZ</th>

</tr>
<%
String sql="";
int tt=0;
while(rs.next())
{ out.println("<tr>");
out.println("<td>"+rs.getString("id")+" </td>");
out.println("<td>"+rs.getString("zd1")+" </td>");
out.println("<td>"+rs.getString("zd2")+" </td>");
out.println("</tr>");
tt++;

}
rs.close();
stmt.close();
con.close();
%>
</table>
<p align="center"><br>
如果您能看到表格中的数据,说明连接数据库成功!</p>
</body>
</html>

发布环境是websphere,这个程序在我机器上是好的,我的机器是xp系统,但是放到另外一台机器上就报JDBC—ODBC错误了,错误如下:

[07-5-9 14:10:30:219 CST] 7760993f WebGroup I SRVE0180I: [web] [/] [Servlet.LOG]: /new.jsp: init
[07-5-9 14:10:30:312 CST] 7760993f WebGroup E SRVE0026E: [Servlet 错误]-[sun.jdbc.odbc.JdbcOdbcDriver]:java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
at com.ibm.ws.classloader.CompoundClassLoader.findClass(CompoundClassLoader.java(Compiled Code))
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java(Compiled Code))
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at com.ibm.ws.webcontainer.jsp.servlet.JasperLoader.loadClass(JasperLoader.java(Compiled Code))
at com.ibm.ws.webcontainer.jsp.servlet.JasperLoader.loadClass(JasperLoader.java(Compiled Code))
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java(Compiled Code))
at org.apache.jsp._new._jspService(_new.java:2938)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java(Inlined Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java(Inlined Compiled Code))
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java(Compiled Code))
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java(Compiled Code))
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java(Compiled Code))
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java(Compiled Code))
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java(Compiled Code))
at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java(Compiled Code))
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java(Compiled Code))
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java(Compiled Code))
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java(Compiled Code))
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java(Compiled Code))
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java(Compiled Code))
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

麻烦大虾们帮我看看是怎么回事
...全文
237 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjwb2003 2007-05-09
  • 打赏
  • 举报
回复
将程序改成直接连Access 文件后,在xp机器上依然正常,拷贝到windows2003上后报错如下:
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriverjava.sql.SQLException: No suitable driver

请教这是因为jdbc-odbc驱动没找到吗?
hjwb2003 2007-05-09
  • 打赏
  • 举报
回复
classpath 中已经增加了jdk/lib
hjwb2003 2007-05-09
  • 打赏
  • 举报
回复
odbc驱动环境变量怎么设呀?
yunxiang 2007-05-09
  • 打赏
  • 举报
回复
没找到驱动。。
你odbc驱动的环境变量设置了么?
hjwb2003 2007-05-09
  • 打赏
  • 举报
回复
另一台机器是windows2003 server

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧