调用executeUpdate时的UCanAccess/Jackcess异常禁用我的Logger输出 [英] UCanAccess/Jackcess exception when calling executeUpdate disables my Logger output

查看:157
本文介绍了调用executeUpdate时的UCanAccess/Jackcess异常禁用我的Logger输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UCanAccess来操作Access数据库. 调用executeUpdate时出现异常:

I am using UCanAccess for manipulating an Access database. When calling executeUpdate I get the exception:

net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.2意外的页面类型1(Db = db.accdb; Table = MyTable; Index = PrimaryKey)

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.2 Unexpected page type 1 (Db=db.accdb;Table=MyTable;Index=PrimaryKey)

它仅在尝试更新一个特定行时发生-我已经知道如何在Access DB中解决此问题.

It only occurs when trying to update one specific row - I already know how to fix this in the Access DB.

问题出在Logger上,引发此异常后,我捕获了它,我记录了一条信息消息,但未显示,所有下一条日志消息也未显示.

The problem is with the Logger, after this exception is thrown and I catch it, I log an info message and it is not shown, all of the next log messages are not shown either.

我要修复而不修复数据库的原因是,当它发生一次时,用户应该关闭应用程序以记录下一个操作,如果他不这样做,那么我将不知道什么他做到了.

The reason why I want to fix it without fixing the DB is because when it occurs once, the user should close the application in order to log the next actions, if he doesn't then I will not be able to know what he did.

这是我的代码:

public static void main(String args[]) {
    Logger logger = Logger.getLogger("myLogger");
    PreparedStatement pst = null;
    try {
        FileHandler fileHandler = new FileHandler("myLog.log", 0, 1, true);

        // Set formatter to put the time, the message, and the exception if exists
        fileHandler.setFormatter(new Formatter() {
            @Override
            public String format(LogRecord record) {
                Throwable t = record.getThrown();
                String stackTrace = "";
                if (t != null) {
                    StringWriter sw = new StringWriter();
                    t.printStackTrace(new PrintWriter(sw));
                    stackTrace = sw.toString();
                }

                return  Calendar.getInstance().getTime() + "--" +
                        formatMessage(record) + stackTrace + "\n";
            }
        });

        // Set the logger handler
        logger.addHandler(fileHandler); 
        logger.log(Level.INFO, "1");

        // Throw on purpose
        String query = "UPDATE myTable SET name = 'a' WHERE id = 289";

        conn = DriverManager.getConnection(DB_URL);
        pst = conn.prepareStatement(query);
        pst.executeUpdate();

        logger.log(Level.INFO, "2");
    } catch (UcanaccessSQLException e) {
        logger.log(Level.INFO, "3");
        System.out.println("INSIDE Exception");
    } catch (SQLException e) {
        logger.log(Level.INFO, "4");
    } catch (Exception e) {
        logger.log(Level.INFO, "5");
    }
}

控制台输出为:

net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.2意外的页面类型1(Db = db.accdb; Table = myTable; Index = PrimaryKey) 在net.ucanaccess.commands.CompositeCommand.persist(CompositeCommand.java:95) 在net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:315) 在net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:205) 在net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:161) 在net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:50) 在net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:253) 在rashi.NewClass.main(NewClass.java:61) 由以下原因引起:java.io.IOException:意外的页面类型1(Db = db.accdb; Table = myTable; Index = PrimaryKey) 在com.healthmarketscience.jackcess.impl.IndexData.isLeafPage(IndexData.java:1185) 在com.healthmarketscience.jackcess.impl.IndexData.readDataPage(IndexData.java:1067) 在com.healthmarketscience.jackcess.impl.IndexPageCache.readDataPage(IndexPageCache.java:267) 在com.healthmarketscience.jackcess.impl.IndexPageCache.getDataPage(IndexPageCache.java:224) 在com.healthmarketscience.jackcess.impl.IndexPageCache.getCacheDataPage(IndexPageCache.java:211) ..............

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.2 Unexpected page type 1 (Db=db.accdb;Table=myTable;Index=PrimaryKey) at net.ucanaccess.commands.CompositeCommand.persist(CompositeCommand.java:95) at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:315) at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:205) at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:161) at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:50) at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:253) at rashi.NewClass.main(NewClass.java:61) Caused by: java.io.IOException: Unexpected page type 1 (Db=db.accdb;Table=myTable;Index=PrimaryKey) at com.healthmarketscience.jackcess.impl.IndexData.isLeafPage(IndexData.java:1185) at com.healthmarketscience.jackcess.impl.IndexData.readDataPage(IndexData.java:1067) at com.healthmarketscience.jackcess.impl.IndexPageCache.readDataPage(IndexPageCache.java:267) at com.healthmarketscience.jackcess.impl.IndexPageCache.getDataPage(IndexPageCache.java:224) at com.healthmarketscience.jackcess.impl.IndexPageCache.getCacheDataPage(IndexPageCache.java:211) ..............

内部异常

我的日志文件仅包含以下行:

And my log file contains only this row:

Sun Dec 20 15:35:40 IST 2015--1

这意味着我的记录器不再处于活动状态.我猜想在UCanAccess中出现异常之前,记录器会有一些更改.

which means my logger is no longer active. I guess there are some logger changes before the exception in UCanAccess.

推荐答案

它看起来像是HSQLDB的副作用,发生在UCanAccess进行物理回滚并关闭镜像数据库时.

It looks like an HSQLDB side-effect that happens while UCanAccess is doing a physical rollback and shutting down the mirror db.

将系统属性hsqldb.reconfig_logging设置为false可能会解决此问题,例如

Setting the system property hsqldb.reconfig_logging to false may solve the issue, e.g.,

-Dhsqldb.reconfig_logging=false

System.setProperty("hsqldb.reconfig_logging", "false");

这篇关于调用executeUpdate时的UCanAccess/Jackcess异常禁用我的Logger输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆