-1
使用的Java與MS Access數據庫,添加 並選擇數據工作得很好,但由於某些原因,我不能更新,它 不斷拋出一個異常UCanAccess UPDATE聲明的異常:「意外的頁面類型1」
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
「意外頁面類型」錯誤最常見的修復方法是在Access中打開數據庫並執行壓縮和修復數據庫操作。 –