【问题标题】:"unsupported collating sort order" error updating Access database from Java从 Java 更新 Access 数据库时出现“不支持的整理排序顺序”错误
【发布时间】:2015-03-09 17:25:21
【问题描述】:

我想通过 NetBeans 使用 UCanAccess 对 Access 表进行一些小的更改,但我遇到了问题

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)

【问题讨论】:

  • 正确格式化您的异常?
  • 能否让同样的 SQL 直接在 Access 中工作?您的 JDBC 驱动程序可能不支持您在主键上配置的 textSortOrder,但我不是 Access 专家。
  • 你为什么不像SALARY那样使用参数TC_NO

标签: java ms-access jdbc ucanaccess


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    解释错误信息:

    java.lang.IllegalArgumentException: Given index ... (PERSON) PrimaryKey ... 由于不支持整理排序顺序而无法用于索引查找

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

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

    • 在 Access 中打开数据库。在File > Options 下,将“新数据库排序顺序”更改为“常规”(或“常规 - 旧版”)。

    • 对数据库执行“压缩和修复数据库”。 (在 Access 2010+ 中,它位于功能区栏的“数据库工具”选项卡上。)

    • 退出访问。

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

    【讨论】:

    • 感谢您的提示。我刚刚注意到了。
    猜你喜欢
    • 2014-01-10
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    相关资源
    最近更新 更多