以access为例:
两种方法:
1.直接使用access的jdbc驱动;
2.使用access的odbc驱动,再使用java的jdbc/odbc桥接器package mypackage;import java.sql.*;/** A JDBC example that connects to the MicroSoft Access sample
 *  Northwind database, issues a simple SQL query to the
 *  employee table, and prints the results.
 *  <P>
 *  Taken from Core Servlets and JavaServer Pages 2nd Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  http://www.coreservlets.com/.
 *  &copy; 2003 Marty Hall and Larry Brown.
 *  May be freely used or adapted. 
 */public class NorthwindTest {
  public static void main(String[] args) {
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:Northwind";
    String username = ""; // No username/password required
    String password = ""; // for desktop access to MS Access.
    showEmployeeTable(driver, url, username, password);
  }  /** Query the employee table and print the first and
   *  last names.
   */
   
  public static void showEmployeeTable(String driver,
                                       String url,
                                       String username,
                                       String password) {
    try {
      // Load database driver if it's not already loaded.
      Class.forName(driver);
      // Establish network connection to database.
      Connection connection =
        DriverManager.getConnection(url, username, password);
      System.out.println("Employees\n" + "==========");
      // Create a statement for executing queries.
      Statement statement = connection.createStatement();
      String query =
        "SELECT firstname, lastname FROM employees";
      // Send query to database and store results.
      ResultSet resultSet = statement.executeQuery(query);
      // Print results.
      while(resultSet.next()) {
        System.out.print(resultSet.getString("firstname") + " ");
        System.out.println(resultSet.getString("lastname"));
      }
      connection.close();
    } catch(ClassNotFoundException cnfe) {
      System.err.println("Error loading driver: " + cnfe);
    } catch(SQLException sqle) {
      System.err.println("Error with connection: " + sqle);
    }
  }
}

解决方案 »

  1.   

    classpath要包含jdbc驱动的类路径
      

  2.   

    <%@ page contentType="text/html;charset=gb2312"%> 
    <%@ page import="java.sql.*"%> 
    <%@ page import="oracle.jdbc.driver.*"%>
    <%@ page import="java.net.*"%>
    <%@ page import="java.lang.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    <html> 
    <body> 
    <%
       try
       {
           Class.forName("oracle.jdbc.driver.OracleDriver");  
           Connection conn= DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ora90","wrq","wrq"); 
          Statement stmt=conn.createStatement(); 
          String sql="select * from TEST"; 
          ResultSet rs=stmt.executeQuery(sql); 
          while(rs.next()) 
         {
    %> 
               您的第一个字段内容为:<%=rs.getString(1)%> 
               您的第二个字段内容为:<%=rs.getString(2)%> 
    <%
          }
          out.print("数据库操作成功,恭喜你");
       }
       catch(java.lang.ClassNotFoundException e)
       {
    System.out.println("myconn():"+e.getMessage());
       }
       catch(java.sql.SQLException e)
       {
    System.out.println("conn():"+e.getMessage());
       }
       catch(Exception e)
       {
    System.out.println("Driver error!");
    System.err.println(e.getMessage());
       } 
    %> 
    </body> 
    </html>