我正在尝试编写一个简单的Java程序,以从Access数据库中提取表和列。使用Jackcess食谱,我得到了以下内容:

        String sourceDatabase = "C:\\temp\\test1.mdb";
        Database accessDB = DatabaseBuilder.open(new File(sourceDatabase));

        // Loop through the tables
        Set<String> accessTables = accessDB.getTableNames();
        for (String currentTable: accessTables) {
            System.out.println("Reading table " + currentTable + "...");

            Table table = accessDB.getTable(currentTable); // This is line 51 where the stacktrace occurs

            // Loop through columns in current table
            for(Column column : table.getColumns()) {
                String columnName = column.getName();

                Integer colType = column.getSQLType();


                Boolean isAutoNumber = column.isAutoNumber();

                System.out.println("\t" + columnName + " \t" + sqlTypeToText(colType) + "\t" + isAutoNumber);

            }

            System.out.println("");


        }
        accessDB.close();


但是,当我尝试运行它时,我得到带有stacktrace的以下输出:

Reading table _OracletblColumn...
    colid   8   false
    tblid   8   false
    colname     12  false
    dbid    8   false

Reading table _OracletblDatabase...
    dbid    8   false
    dbname  12  false
    dbpathname  12  false

Reading table _OracletblTable...
    tblid   8   false
    dbid    8   false
    tblname     12  false

Reading table DICT_ACCOM...
java.io.IOException: The specified network name is no longer available
    at sun.nio.ch.FileDispatcher.pread0(Native Method)
    at sun.nio.ch.FileDispatcher.pread(FileDispatcher.java:35)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:195)
    at sun.nio.ch.IOUtil.read(IOUtil.java:171)
    at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:612)
    at com.healthmarketscience.jackcess.impl.PageChannel.readPage(PageChannel.java:211)
    at com.healthmarketscience.jackcess.impl.TempPageHolder.setPage(TempPageHolder.java:86)
    at com.healthmarketscience.jackcess.impl.TempPageHolder.setPage(TempPageHolder.java:74)
    at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.<init>(UsageMap.java:693)
    at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.<init>(UsageMap.java:673)
    at com.healthmarketscience.jackcess.impl.UsageMap.initHandler(UsageMap.java:146)
    at com.healthmarketscience.jackcess.impl.UsageMap.read(UsageMap.java:136)
    at com.healthmarketscience.jackcess.impl.UsageMap.read(UsageMap.java:108)
    at com.healthmarketscience.jackcess.impl.TableImpl.<init>(TableImpl.java:245)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.readTable(DatabaseImpl.java:1538)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:849)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:526)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:393)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:252)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:291)
    at com.healthmarketscience.jackcess.util.LinkResolver$1.resolveLinkedDatabase(LinkResolver.java:42)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:1003)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:971)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:929)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:82)
    at com.ralph.sql.test1.migrateTableDefs(test1.java:51)
    at com.ralph.sql.test1.main(test1.java:24)


我已经尝试使用Google搜索,但没有发现其他人遇到与Jackcess相同的问题,我在做什么错?

最佳答案

经过进一步调查,发现上面的代码没有错误。

当我将Access数据库移动到另一个文件夹时,上面的代码可以完美地运行而无需堆栈跟踪。我首先想到的是文件许可权,我检查了我的用户对数据库(和C:\ temp文件夹)的读写权限。

原来是我的公司病毒扫描(McAfee)进行了某种形式的访问扫描后才破坏了它。由于不允许我禁用病毒扫描程序,因此我将所有工作移至C:\ users \ username内的文件夹中,因为病毒扫描允许我访问这些文件。拥有本地管理员许可太多了,但无济于事。

关于java - 使用Jackcess时,“指定的网络名称不再可用”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38372340/

10-10 11:49