请安装jdbc桥。建议不要用jdbc桥。直接使用jdbc,需设classpath

解决方案 »

  1.   

    请试以下方法:
    原来的语句:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    改成:
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    }catch(Exception e){
    e.printStackTrace();
    }
    问题应该出在这儿.                      
      

  2.   

    你的机上已经做好一个名叫db的数据库(或是远端数据库),并设好系统的odbc吗?
      

  3.   

    to zhangjb:
    按照你的方法之后出现了下面的错误
    Unhandled error! You might want to consider having an error page to report such
    errors more gracefully
    com.sun.jsp.JspException: Compilation failed:work\202.202.35.152%3A7878%2F\data_
    0002ejspdata_jsp_1.java:94: Variable rest may not have been initialized.
                     while(rest.next()){
                           ^
    1 error        at com.sun.jsp.compiler.Main.compile(Compiled Code)
            at com.sun.jsp.runtime.JspLoader.loadJSP(JspLoader.java:135)
            at com.sun.jsp.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspS
    ervlet.java:77)
            at com.sun.jsp.runtime.JspServlet$JspServletWrapper.service(JspServlet.j
    ava:87)
            at com.sun.jsp.runtime.JspServlet.serviceJspFile(JspServlet.java:218)
            at com.sun.jsp.runtime.JspServlet.service(JspServlet.java:294)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
            at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155
    )
            at com.sun.web.core.Context.handleRequest(Context.java:414)
            at com.sun.web.server.ConnectionHandler.run(Compiled Code)
    唉,现在真是烦死了
      

  4.   

    <%!
    java.sql.Connection sqlconn;
    ……………………
    %>
    的叹号去掉,
    改成
    <%
    …………
    %>
    试试
      

  5.   

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    .newInstance();去掉!!
      

  6.   

    我找出了问题所在
    1、将叹号去掉
    2、在最后的close中关闭顺序错误
    我将修改好的代码附在下面,再试一下
    <%@page contentType="text/html;charset=gb2312" import="java.sql.*"%>
    <%
    java.sql.Connection sqlconn;
    java.sql.Statement stmt;
    java.sql.ResultSet rest;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    sqlconn=java.sql.DriverManager.getConnection("jdbc:odbc:db");stmt=sqlconn.createStatement();
    rest=stmt.executeQuery("select a,b from bb");
    %><html>
    <head>
    <title>jdbc-odbc test!</title>
    </head>
    <body><table border="1" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <th>姓名</th>
    <th>年龄</th>
    </tr>
    <%while(rest.next()){%>
    <tr>
    <td><%=rest.getString(1)%></td>
    <td><%=rest.getString(2)%></td>
    </tr>
    <%}%>
    </table>
    </body>
    </html>
    <%
    sqlconn.close();
    stmt.close();
    //rest.close();
    %>