"unsupported collating sort order" 从 Java 更新 Access 数据库时出错

"unsupported collating sort order" error updating Access database from Java

我想通过 NetBeans 使用 UCanAccess 对 Access table 做一个小改动,但我在第

行遇到了问题
pst.executeUpdate();

数据库详细信息:

database name : duruBistro.accdb
table name : person
field names: tc_no    (text)
             name     (text)
             surname  (text)
             salary   (number)

代码:

Connection conn = DriverManager.getConnection("jdbc:ucanaccess://C:\Users\ysnndr    \Documents\accessDB\duruBistro.accdb");
String query = "UPDATE PERSON SET SALARY = ? WHERE TC_NO = '189'";
PreparedStatement pst = conn.prepareStatement(query);
pst.setInt(1, 2500);         
pst.executeUpdate();

异常:

run:
java.lang.IllegalArgumentException: Given index Index@53f65459[
  name: (PERSON) PrimaryKey
  number: 0
  isPrimaryKey: true
  isForeignKey: false
  data: IndexData@3b088d51[
    dataNumber: 0
    pageNumber: 317
    isBackingPrimaryKey: true
    isUnique: true
    ignoreNulls: false
    columns: [
      ReadOnlyColumnDescriptor@1786dec2[
        column: TextColumn@711f39f9[
          name: (PERSON) TC_NO
          type: 0xa (TEXT)
          number: 17
          length: 22
          variableLength: true
          compressedUnicode: true
          textSortOrder: SortOrder[1055(0)]
        ]
        flags: 1
      ]
    ]
    initialized: false
    pageCache: IndexPageCache@74650e52[
      pages: (uninitialized)
    ]
  ]
] is not usable for indexed lookups due to unsupported collating sort order SortOrder[1055(0)] for text index
    at com.healthmarketscience.jackcess.impl.IndexCursorImpl.createCursor(IndexCursorImpl.java:111)
net.ucanaccess.jdbc.UcanaccessSQLException: Given index Index@53f65459[
  name: (PERSON) PrimaryKey
  number: 0
  isPrimaryKey: true
  isForeignKey: false
  data: IndexData@3b088d51[
    dataNumber: 0
    pageNumber: 317
    at com.healthmarketscience.jackcess.CursorBuilder.toCursor(CursorBuilder.java:302)
    at net.ucanaccess.commands.IndexSelector.getCursor(IndexSelector.java:148)
    isBackingPrimaryKey: true
    isUnique: true
    at net.ucanaccess.commands.CompositeCommand.persist(CompositeCommand.java:83)
    ignoreNulls: false
    columns: [
      ReadOnlyColumnDescriptor@1786dec2[
        column: TextColumn@711f39f9[
          name: (PERSON) TC_NO
          type: 0xa (TEXT)
          number: 17
          length: 22
          variableLength: true
          compressedUnicode: true
          textSortOrder: SortOrder[1055(0)]
        ]
        flags: 1
      ]
    ]
    initialized: false
    pageCache: IndexPageCache@74650e52[
      pages: (uninitialized)
    ]
  ]
] is not usable for indexed lookups due to unsupported collating sort order SortOrder[1055(0)] for text index
    at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:312)
    at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:202)
    at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:143)
    at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:56)
    at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:248)
    at com.ui.AccdbcConnection.main(AccdbcConnection.java:29)
BUILD SUCCESSFUL (total time: 1 second)

解释错误信息:

java.lang.IllegalArgumentException: Given index ... (PERSON) PrimaryKey ... is not usable for indexed lookups due to unsupported collating sort order

这是 Jackcess 的一个已知限制,Jackcess 是 UCanAccess 用来读写 Access 数据库文件的记录管理器。为了对主键类型为 Text 的表执行更新,Jackcess 要求 Access 数据库使用 "General" 或 "General - Legacy" 排序顺序。

更改相关 Access 数据库文件的排序顺序:

  • 在 Access 中打开数据库。在 File > Options 下将 "New database sort order" 更改为 "General"(或 "General - Legacy")。

  • 对数据库执行"Compact and Repair Database"。 (在 Access 2010+ 中,它位于功能区栏的 "Database Tools" 选项卡上。)

  • 退出访问。

您的 Java 应用程序不应再抛出异常。但是,如果问题仍然存在,那么您的 Windows 语言环境也可能存在问题。请参阅 了解另一种可能的解决方案。

3 分钟前我找到了解决方案,您必须更改主键类型(例如从 String 到 Integer),仅此而已。