-1

Using Java with MS Access database, adding and selecting data is working just fine, but for some reason I can't update, it keeps throwing an exception

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.2 Unexpected page type 1

I've never seen this exception before and Googling was not helpful.

First the code :

public class DatabaseHandler {

private static Connection conn = null;
static PreparedStatement sqlState;
static ResultSet rs;

public static Connection connect() {

    try {
        //creating a connection
        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
        conn = (Connection) DriverManager.getConnection("jdbc:ucanaccess://src/salah_al_deen.accdb");
        System.out.println("Connected to the database");

    } catch (ClassNotFoundException | SQLException e) {
        System.out.println("Error: " + e.getMessage());
    }

    return conn;
}

static void prepareStatement(String query) {
    try {
        //create a statement using the connection created
        if (conn == null) {
            connect();
        }

        sqlState = conn.prepareStatement(query);
    } catch (SQLException ex) {
        System.out.println("Error: " + ex.getMessage());
    }
}

public static void close() {
    try {
        //close the connection and the statement
        sqlState.close();
        conn.close();
        System.out.println("Done");
        conn = null;
    } catch (SQLException ex) {
        System.out.println("Error:" + ex.getMessage());
    }

}}

public class UpdateDatabase extends DatabaseHandler {

public static void updateClient(String tableName, Client client) {

    try {
        prepareStatement("UPDATE " + tableName + "_clients SET name=? , birthdate=? , start_date=? , phone=?, emergency_phone=?, email=?, fb_name=?, trans=?, address=?, session=?, payment_notify=?, valid=? WHERE _id=?");

        sqlState.setString(1, client.getName());
        sqlState.setDate(2, client.getBirthdate());
        sqlState.setDate(3, client.getStart_date());
        sqlState.setInt(4, client.getPhone());
        sqlState.setInt(5, client.getEmergency_phone());
        sqlState.setString(6, client.getEmail());
        sqlState.setString(7, client.getFb_name());
        sqlState.setInt(8, client.getTrans());
        sqlState.setString(9, client.getAddress());
        sqlState.setInt(10, client.getSession());
        sqlState.setInt(11, client.getPaymentNotify());
        sqlState.setInt(12, client.getValid());
        sqlState.setInt(13, client.getId());

        sqlState.executeUpdate();

        printMessage(tableName);

    } catch (SQLException ex) {
        System.out.println(ex.getMessage());
    }
}

Exception :

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.2 Unexpected page type 1 (Db=salah_al_deen.accdb;Table=karate_clients;Index=class_id)
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.Execute.execute(Execute.java:46)
at net.ucanaccess.jdbc.UcanaccessPreparedStatement.execute(UcanaccessPreparedStatement.java:228)
at client.general.database.UpdateDatabase.updateClient(UpdateDatabase.java:35)
at clients.view.main.ClientsMainController.activateAction(ClientsMainController.java:293)

Caused by: java.io.IOException: Unexpected page type 1 (Db=salah_al_deen.accdb;Table=karate_clients;Index=class_id)
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.access$600(IndexPageCache.java:38)
at com.healthmarketscience.jackcess.impl.IndexPageCache$DataPageMain.getChildPage(IndexPageCache.java:1250)
at com.healthmarketscience.jackcess.impl.IndexPageCache$DataPageMain.getChildPage(IndexPageCache.java:1234)
at com.healthmarketscience.jackcess.impl.IndexPageCache.findCacheDataPage(IndexPageCache.java:921)
at com.healthmarketscience.jackcess.impl.IndexData.findDataPage(IndexData.java:1256)
at com.healthmarketscience.jackcess.impl.IndexData.removeEntry(IndexData.java:740)
at com.healthmarketscience.jackcess.impl.IndexData.deleteRowImpl(IndexData.java:701)
at com.healthmarketscience.jackcess.impl.IndexData.prepareUpdateRow(IndexData.java:662)
at com.healthmarketscience.jackcess.impl.TableImpl.updateRow(TableImpl.java:1833)
at com.healthmarketscience.jackcess.impl.CursorImpl.updateCurrentRow(CursorImpl.java:268)
at net.ucanaccess.commands.UpdateCommand.persist(UpdateCommand.java:193)
at net.ucanaccess.commands.UpdateCommand.persistCurrentRow(UpdateCommand.java:122)
at net.ucanaccess.commands.CompositeCommand.persist(CompositeCommand.java:86)
... 69 more
Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
Abdullah Asendar
  • 485
  • 1
  • 5
  • 24
  • The most common fix for "Unexpected page type" errors is to open the database in Access and do a Compact and Repair Database operation. – Gord Thompson Nov 19 '15 at 22:42

1 Answers1

0

As you can see from the stacktrace, that is a Jackcess error that is being handed back to UCanAccess. It is not a UCanAccess issue per se.

Try opening the database in Access and performing a "Compact and Repair Database" operation. If that does not fix the issue then consider re-tagging this question for .

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342