jsp连接access 数据库问题。。。。
用java Bean 来做的连接就会出下面的错。。但直接写在jsp文件中则可以成功。。
请大家帮忙
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: [Microsoft][ODBC ???????] ???????
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:673)
org.apache.jsp.index_jsp._jspService(index_jsp.java:267)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.sql.SQLException: [Microsoft][ODBC ???????] ???????
sun.jdbc.odbc.JdbcOdbc.create
SQLException(JdbcOdbc.java:6958)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3908)
sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5699)
sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:353)
sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:410)
org.apache.jsp.index_jsp._jspService(index_jsp.java:124)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
------解决方案--------------------代码呢?看看?
------解决方案--------------------好久没有用过Bean连数据库了,试试下面的
package beans;
import java.sql.*;
public class connDB{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public connDB(){
try{
//Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver "); //载入驱动程序类别
conn = DriverManager.getConnection( "jdbc:odbc:db_board ");
stmt=conn.createStatement();
}catch(
java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(e