当前位置: 首页 > 工具软件 > UCanAccess > 使用案例 >

Java使用UCanAccess连接mdb数据库

暨弘懿
2023-12-01

话不多说,直接上代码:

 

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

String url = UcanaccessDriver.URL_PREFIX + "F:\\db1.mdb;newDatabaseVersion=V2003";
Connection connection = DriverManager.getConnection(url, username, password);

Statement statement = connection.createStatement();

ResultSet result = statement.executeQuery("SELECT * FROM M_PERSON");


while (result.next()) {
    System.out.print(result.getString("PSNSN") + "\t");
    System.out.print(result.getString("CORPSN") + "\t");
    System.out.print(result.getString("IDCARD") + "\t");
    System.out.print(result.getString("SSN") + "\t");
    System.out.print(result.getString("NAME") + "\t");
    System.out.print(result.getString("SEX") + "\t");
    System.out.println();
}

 

注:如果是在linux下连接,需要设置文件的操作执行权限。

 类似资料: