我已经建立了用access建立了图书管理系统的数据库,并建立了图书明细表.也弄了数据源.执行别的jsp的文件都成功,但唯独连接数据库的都没用。请各位帮帮我
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>JSP连接Access数据库(一)显示记录</title>
</head>
<body>
<div align="center" >JSP连接Access数据库</div>
<div align="center" >
<br> <hr>
<p>
<%
//载入驱动程序类别
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//建立数据库连接,jspdata为ODBC数据源名称
Connection con = DriverManager.getConnection("jdbc:odbc:jspdata");
//建立Statement对象
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
//建立ResultSet(结果集)对象,并执行SQL语句
ResultSet rs = stmt.executeQuery("select * from 图书明细表");
%>
</p>
<p align="center">图书管理系统图书明细表中记录如下</p>
<table width="640" border="1" align="center" bordercolor="#7188e0">
<tr bgcolor="d1d1ff">
<Td width="80">图书编号</th>
<th width="300">图书名称</th>
<th width="200">出版社</th>
<th width="200">定价</th>
<th width="200">日期</th>
</tr><%
while(rs.next())
{ %>
<tr bgcolor="#f8f8f8">
<td><%= rs.getString(1) %></td>
<td><%= rs.getString(2) %></td>
<td><%= rs.getString(3) %></td>
<td bgcolor="#f6f6f8"><%= rs.getString(4) %></td>
<td><%= rs.getString(5) %></td>
</tr>
<%
}
rs.close();
stmt.close();
con.close();
%>
</table>
<p align="center"><br>
如果能看到表格中的数据,说明连接数据库成功!</p>
</body>
</html>
执行后显示
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /jspdata.jsp:1512:  //载入驱动程序类别
13:  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
14:  //建立数据库连接,jspdata为ODBC数据源名称
15:  Connection con = DriverManager.getConnection("jdbc:odbc:jspdata");
16:  //建立Statement对象
17:  Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
18: ResultSet.CONCUR_READ_ONLY);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
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 javax.servlet.ServletException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
org.apache.jsp.jspdata_jsp._jspService(jspdata_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
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 java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.jspdata_jsp._jspService(jspdata_jsp.java:58)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.20

解决方案 »

  1.   

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                String s = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=d:/jsp/oa/database/oa_database.mdb";
      

  2.   

    try{
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
        catch(ClassNotFoundException e){
          System.out.print(e);
        }
        try{
          String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C://Inetpub//wwwroot//Yeyinews//news.mdb";
          Connection conn = DriverManager.getConnection(url);
          Statement stmt = conn.createStatement();
          .........
    }
    catch(Xeception e){
    }上面的代码实际使用过,应该没有什么问题
      

  3.   

    那个连接数据库还可以全用代码的哈
    String str=path("/");
    String realpath=repace("\\","/");
    String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=realpath"+"**.mdb";
          Connection conn = DriverManager.getConnection(url);
          Statement stmt = conn.createStatement();
      

  4.   

    jdbc:odbc:jspdata有问题,数据源连接问题
      

  5.   

    如果是Jbdc:Odbc的问题那应该怎样解决,是不是要重装系统哟
      

  6.   

    注意建数据源时应选择“系统数据源”,即“系统DSN”。
      

  7.   

    照楼上的说法做了,结果还是不行。出错显示
    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /jspdata.jsp:1613:  //载入驱动程序类别
    14:  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    15:  //建立数据库连接,jspdata为ODBC数据源名称
    16:  Connection con=DriverManager.getConnection("jdbc:odbc:jspdata");
    17:  //建立Statement对象
    18:  Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    19: ResultSet.CONCUR_READ_ONLY);
    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
    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 javax.servlet.ServletException: General error
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
    org.apache.jsp.jspdata_jsp._jspService(jspdata_jsp.java:116)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
    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 java.sql.SQLException: General error
    sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
    sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
    sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    org.apache.jsp.jspdata_jsp._jspService(jspdata_jsp.java:59)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
    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)
      

  8.   

    这段程序应该没问题,估计是ODBC设置问题 注意看看都是半角么?该不会用中文的输入的符号吧
      

  9.   

    看一下你的tomcat 的webapps\ 是否加入了你的jsp项目吧.