JSP connection to access database (not through the method of establishing ODBC data source)


one   Create the folder “accessdb” under the site (my site is e: \ javatest), and the database “test. MDB” and table “stu” under the folder. The stu field is   id,stuname        The path of test.mdb is e: \ javatest \ accessdb   below
As shown below:

2. Establish the test connection database file “accesstest. JSP” under the site (E: \ javatest)
The code is as follows:

<%@ page contentType=”text/html; charset=gb2312″ language=”java” import=”java.sql.*” errorPage=”” %>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd“>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
< title > access connection test < / Title >

catch(ClassNotFoundException e){
  // Absolute path
  //String url = “jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E:/javatest/AccessDb/test.mdb”;
  // among   E:/javatest/AccessDb/test.mdb   Is the absolute path where the database is located

  // Relative path
   String   strDirPath=getServletContext().getRealPath(“/”);               // Get the absolute path of the site: e: \ javatest\

   strDirPath=strDirPath.replace(‘\\’,’/’);                              // Replace ‘\’ with ‘/’        E:/javatest/

  String url = “jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=”+strDirPath+”AccessDb/test.mdb”;

  //String url = “jdbc:odbc:accesstest”;
  // Establish ODBC data source connection

  Connection conn = DriverManager.getConnection(url);
  Statement stmt = conn.createStatement();
   ResultSet   rs  =  stmt.executeQuery(“Select  *  FROM   stu”);               // Get the record in the stu table
    out.print(rs.getInt(1)+” “);
catch(Exception ex){

The operation results are as follows:

Recommended Today

IOS segmented pop-up window

Recently, I encountered a demand similar to the segmented pop-up window of Gaode map (as shown in the figure below). I didn’t find relevant information on the Internet, so I wrote one myself, hoping to provide you with ideas. Realization effect The idea is that when the pop-up window is in the first segment, add […]