UCanAccess UPDATE语句异常:“意外的页面类型1”

时间:2015-11-19 21:57:52

标签: java jdbc ucanaccess

将Java与MS Access数据库一起使用, 添加和选择数据工作得很好,但由于某种原因,我无法更新, 它不断抛出异常

  

net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.2意外的网页类型1

我之前从未见过这个例外,谷歌搜索没有帮助。

首先是代码:

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());
    }
}

例外:

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

1 个答案:

答案 0 :(得分:0)

正如您从堆栈跟踪中看到的那样,这是一个Jackcess错误,正在被交还给UCanAccess。这不是UCanAccess问题本身

尝试在Access中打开数据库并执行“压缩和修复数据库”操作。如果这不能解决问题,请考虑为重新标记此问题。