I am using UCanAccess to manage an Access database. When executeUpdate called executeUpdate I get an exception:
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc: 3.0.2 Unexpected page type 1 (Db = db.accdb; Table = MyTable; Index = PrimaryKey)
This only happens when trying to update one specific row - I already know how to fix this in the access database.
The problem with Logger is, after this exception is thrown, and I catch it, I register an informational message and it does not appear, all the following log messages also do not appear.
The reason why I want to fix this without fixing the database is that when this happens once, the user must close the application in order to register the following actions, if he doesn’t, I won’t know what he did.
This is my code:
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"); } }
Console output:
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 data15) at net.ucanaccess.jdbc.UcanaccessConnection.commit (UcanaccessConnection.java:205) at net.ucanaccess.jdbc.AbstractExecute.executeBasej16 at net.ucanaccess.jdbc.ExecuteUpdate.execute (ExecuteUpdate.java:50) at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate (UcanaccessPreparedStatement.java:253) on rashi.NewClass.main: NewClass .io.IOException: Unexpected page type 1 (Db = db.accdb; Table = myTable; Index = PrimaryKey) on com.healthmarketscience.jackcess.impl.IndexData.isLeafPage (IndexData.java:1185) on com.healthmarketscien ce.jackcess.impl.IndexData.readDataPage (IndexData.java:1067) at com.healthmarketscience.jackcess.impl.IndexPageCache.readDataPage (IndexPageCache.java:267) at com.healthmarketscience.jackcess.impl.IndexPageCache java: 224) on com.healthmarketscience.jackcess.impl.IndexPageCache.getCacheDataPage (IndexPageCache.java:211) ..............
INSIDE Exception
And my log file contains only this line:
Sun Dec 20 15:35:40 IST 2015--1
which means my registrar is no longer active. I think there are some registrar changes before exception in UCanAccess.