我正在使用UCanAccess来操作Access数据库.在调用时executeUpdate
我得到了异常:
net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.2意外的页面类型1(Db = db.accdb; Table = MyTable; Index = PrimaryKey)
它只在尝试更新一个特定行时发生 - 我已经知道如何在Access DB中修复此问题.
问题在于Logger,在抛出此异常后我抓住了它,我记录了一条信息消息但未显示,所有下一条日志消息也未显示.
我想在不修复数据库的情况下修复它的原因是因为当它发生一次时,用户应该关闭应用程序以便记录下一个动作,如果他没有,那么我将无法知道他做了什么.
这是我的代码:
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 net.ucanaccess.commands.CompositeCommand.persist(CompositeCommand.java:95)的意外页面类型1(Db = db.accdb; Table = myTable; Index = PrimaryKey) )net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:315)at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:205)net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java: 161)在net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:50)at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:253)at rashi.NewClass.main(NewClass.java:61) by:java.io.IOException:com.healthmarketscience上com.healthmarketscience.jackcess.impl.IndexData.isLeafPage(IndexData.java:1185)的意外页面类型1(Db = db.accdb; Table = myTable; Index = PrimaryKey) .jackcess.impl.IndexData.readDataPage(IndexData.java:1067)at com.healthmarketscience.jackcess.impl.IndexPageCache.readDataPage(Inde xPageCache.java:267)com.healthmarketscience.jackcess.impl.IndexPageCache.getDataPage(IndexPageCache.java:224)at com.healthmarketscience.jackcess.impl.IndexPageCache.getCacheDataPage(IndexPageCache.java:211)...... ........
INSIDE例外
我的日志文件只包含这一行:
Sun Dec 20 15:35:40 IST 2015--1
这意味着我的记录器不再有效.我想在UCanAccess中的异常之前有一些记录器更改.