jsp连接access数据库不需要装jdbc
给你个servlet的例子吧,可以直接运行的.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ConnectAccess extends HttpServlet {
Connection conn = null;
Statement stmt = null;
public void init() throws ServletException {
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\books.mdb";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;");
PrintWriter out = response.getWriter();
try {
ResultSet rs=stmt.executeQuery("select * from books");
out.println("<html><body>");
out.println("<p>Database connection successfully created!</p>");
while (rs.next()) {
out.println("<p>The book's name is: " + rs.getString("book") +"</p>");
}
out.println("</body></html>");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void destroy() {
try {
conn.close();
} catch(SQLException e){}
}
}