"不支持整理排序顺序"从Java更新Access数据库时出错

时间:2015-01-12 00:13:41

标签: java ms-access jdbc ucanaccess

我想通过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)

2 个答案:

答案 0 :(得分:9)

解释错误信息:

  

java.lang.IllegalArgumentException:给定索引...(PERSON)由于不支持整理排序顺序,PrimaryKey ...不能用于索引查找

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

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

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

Options.png

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

  • 退出访问。

您的Java应用程序不应再抛出异常。但是,如果问题仍然存在,那么Windows区域设置可能也存在问题。有关其他可能的解决方案,请参阅this answer

答案 1 :(得分:0)

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