import java.sql.*;
Connection  connection=null;
   PreparedStatement statement=null;
   try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      connection=DriverManager.getConnection("jdbc:odbc:testAccess","sa","");
      Enumeration eDri = DriverManager.getDrivers();
      while(eDri.hasMoreElements())
        System.out.println("驱动程序:" + eDri.nextElement().toString());
     
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }    try{
      String sql="select * from people";
      statement=connection.prepareStatement(sql);
      ResultSet result=statement.executeQuery();
      while(result.next())
      {
        int    nid=result.getInt("id");
        String strid=new String("id  "+nid);
        System.out.println(strid);
        String name=result.getString("name");
        System.out.println("name  "+name);
        String sex=result.getString("sex");
        System.out.println("sex  "+sex);       // int age=result.getInt("age");
       // String strAge=new String(""+age);
       // System.out.println("age  "+strAge);        String phone=result.getString("phone");
        System.out.println("phone  "+phone);
        String other=result.getString("other");
        System.out.println("other  "+other);      }
      result.close();
      statement.close();     }catch(Exception e)
    {
      System.out.println(e.toString());    }

解决方案 »

  1.   

    必须用jdbc-odbc桥!
    设置好dsn后!String 
    String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; 
    String ConnStr = "jdbc:odbc:Customers"; 
    conn = DriverManager.getConnection(ConnStr);
      

  2.   

    必须用JDBC-ODBC
    设置好DSN
    String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; 
    String ConnStr = "jdbc:odbc:Customers"; 
    conn = DriverManager.getConnection(ConnStr);   当然CONNSTR里可以有UID PWD等参数的呀