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

java解析mdb文件,Java中Jackcess读取.mdb文件,不依赖JDK 32位或JDK 64位

萧和平
2023-12-01

以前Java读取.mdb文件,太依赖JDK的位数了,必须用32位的;

现在运用jackcess来解析.mdb文件,这样不被限制;

pom.xml文件:

commons-io

commons-io

2.3

com.healthmarketscience.jackcess

jackcess

2.1.10

net.sf.ucanaccess

ucanaccess

4.0.0

com.healthmarketscience.jackcess

jackcess-encrypt

2.1.4

代码如下:

package com.accord.utils;

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import net.ucanaccess.jdbc.JackcessOpenerInterface;

import com.accord.entity.Corp;

import com.healthmarketscience.jackcess.CryptCodecProvider;

import com.healthmarketscience.jackcess.Database;

import com.healthmarketscience.jackcess.DatabaseBuilder;

import com.healthmarketscience.jackcess.Row;

import com.healthmarketscience.jackcess.Table;

/**

* @author 王久印

* 2018年4月9日

* 读取.mdb配置文件工具类

*/

public class ReadMdbUtil implements JackcessOpenerInterface {

//private static ListCORPLISTS = new ArrayList() ;

@Override

public Database open(File file, String pwd) throws IOException {

DatabaseBuilder dbd =new DatabaseBuilder(file);

dbd.setAutoSync(false);

dbd.setCodecProvider(new CryptCodecProvider(pwd));

dbd.setReadOnly(false);

return dbd.open();

}

public static ListgetCorpLists(String filename) {

ListcorpLists = new ArrayList();

File file = new File(filename);

String pwd = "test0011";

ReadMdbUtil rm = new ReadMdbUtil();

Database db = null;

Table tables = null;

try {

db = rm.open(file, pwd);

tables = db.getTable("t_corp");

} catch (IOException e1) {

e1.printStackTrace();

}

for(Row rs : tables) {

Corp corp = new Corp();

corp.setId(rs.getInt("ID").toString());

corp.setFcorp(rs.getString("FCORP"));

corp.setFgsbm(rs.getString("FGSBM"));

corp.setFgsmc(rs.getString("FGSMC"));

corp.setFismerge(rs.getString("FISMERGE"));

corp.setFsid(rs.getString("FSID"));

corp.setFuser(rs.getString("FUSER"));

corp.setFpwd(rs.getString("FPWD"));

corp.setFbilltype(rs.getString("FBILLTYPE"));

corp.setFprocedure(rs.getString("FPROCEDURE"));

corp.setFip(rs.getString("FIP"));

corp.setFimpcust(rs.getString("FIMPCUST"));

corp.setFimpemp(rs.getString("FIMPEMP"));

corp.setFimppz(rs.getString("FIMPPZ"));

corpLists.add(corp);

}

return corpLists;

}

public static void main(String[] args) {

ListcorpLists = getCorpLists("D:\\system.mdb");

for (Corp corp : corpLists) {

System.out.println(corp.getId() + corp.getFcorp() + corp.getFgsbm() + corp.getFgsmc()

+ corp.getFismerge() + corp.getFsid() + corp.getFuser() + corp.getFpwd()

+ corp.getFbilltype() + corp.getFprocedure() + corp.getFip() + corp.getFimpcust()

+ corp.getFimpemp() + corp.getFimppz());

}

}

}

 类似资料: