首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Java更新Access数据库时出现“不支持的排序顺序”错误

问从Java更新Access数据库时出现“不支持的排序顺序”错误
EN

Stack Overflow用户
提问于 2015-01-12 08:13:41
回答 2查看 9.7K关注 0票数 5

我想通过NetBeans使用UCanAccess在Access表中做一点小更改,但我在第行遇到了问题

代码语言:javascript
复制
pst.executeUpdate();

数据库详细信息:

代码语言:javascript
复制
database name : duruBistro.accdb
table name : person
field names: tc_no    (text)
             name     (text)
             surname  (text)
             salary   (number)

代码:

代码语言:javascript
复制
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();

例外:

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-12 20:06:44

要解释错误消息,请执行以下操作:

java.lang.IllegalArgumentException:给定索引...(个人) PrimaryKey ...由于不支持排序顺序,因此不适用于索引查找

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

要更改相关Access数据库文件的排序顺序,请执行以下操作:

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

​

​

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

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

票数 11
EN

Stack Overflow用户

发布于 2020-03-11 01:53:27

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27893630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档