就象从ORACLE中读数据一样,只不过驱动不一样罢了!

解决方案 »

  1.   

    步骤是一样的。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());    }
      

  2.   

    感谢帮忙!不过我第一次用Access。请讲详细一点!
    1.怎么建立数据源。就象Sql server的ODBC。需要不?
    2.怎么连接?
      

  3.   

    凡是通过jdbc-odbc桥连接数据库都需要配置数据源
    注意应配置成系统DSN
    配法和一般的ODBC数据源一样的配法。
      

  4.   

    凡是通过jdbc-odbc桥连接数据库都需要配置数据源
    注意应配置成系统DSN
    配法和一般的ODBC数据源一样的配法。
    配好后,就不用管了,将楼上代码中的testAccess换成你自己的数据源名
    就可以了。