3楼的方法不行,错误还是一样
java.sql.SQLException: No suitable driver
4楼的把第三行拿掉,是这行吗?
Class.forName(driver).newInstance();
拿掉后有了新的错误,这个错误又不知是什么意思
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 47 in the jsp file: /TestDbConnect.jsp
Generated servlet error:
Unreachable catch block for ClassNotFoundException. This exception is never thrown from the try statement body
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
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
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 47 in the jsp file: /TestDbConnect.jsp
Generated servlet error:
Unreachable catch block for ClassNotFoundException. This exception is never thrown from the try statement body
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
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.17 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.17
程序是这样的
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,javax.sql.*"%>
<%@ page import="java.util.*"%>
<html>
<body>
<%
String url = "dbc:odbc:Driver={MicroSoft Access Driver(*.mdb)};DBQ=E:\\javatest\\Test.mdb";
//String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String user = "";
String password = "";
try {
//Class.forName(driver).newInstance();
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from users";
ResultSet rs=stmt.executeQuery(sql);
int Msg = 0;
while(rs.next()) {%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<%=rs.getString(3)%>
<%=rs.getString(4)%>
<%=rs.getString(5)%>
<%=rs.getString(6)%>
<%=rs.getString(7)%>
<%=rs.getString(8)%>
<% Msg = 1;%>
<p>
<%}%>
<%if (Msg == 0) out.print("No Data!<br>");%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
}
catch (ClassNotFoundException s) {
out.println(s);
}
catch (SQLException e) {
out.println(e);
}
%>
</body>
</html>