import java.sql.*; public class ConnectAccess { public static void main(String args[]){
ConnectAccess ca = new ConnectAccess();
try {
ca.connectAccess();
} catch (Exception e) {
e.printStackTrace();
}
} public void connectAccess() throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); /**
* 直接连接access文件。
*/
String url = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=access\\access.accdb;PWD=123456;"; /**
* 使用ODBC连接数据源
*/
// String ur1 = "jdbc:odbc:DataSource"; Connection conn = DriverManager.getConnection(url, "","");
Statement stmt = conn.createStatement();
String sql = "select * from t_system_user_info";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
rs.close();
stmt.close();
conn.close();
} }
仅供学习参考。