为什么使用JDBC插入单行时会出现ORA-01422错误

问题描述 投票:2回答:1

[我看到许多与该特定错误有关的问题-它们大多数与SELECT INTO操作有关。

不过,在这种情况下,我试图插入一行,但没有找到针对此特定问题的任何答案。

我正在使用以下代码:

final String insertSQL = "INSERT INTO XMLTYPETEST_XMLTYPE (ACTIVITYGUID, XMLDATA) VALUES (:1, XMLType(:2))";
final String guid = "BFACFEB-8ACE-4145-B04A-759822E0AA7D";
final String xml = "<Activity><Changes></Changes></Activity>";
try (OraclePreparedStatement stmt = 
        (OraclePreparedStatement) conn.prepareStatement(insertSQL)) {
    stmt.setString(1, guid);
    stmt.setString(2, xml);
    stmt.execute();

} catch (SQLException ex) {
    Logger.getLogger(DBConnectionTest.class.getName())
          .log(Level.SEVERE, null, ex);
    fail();
}

表XMLTYPETEST_XMLTYPE定义如下:



  CREATE TABLE "PLAYGROUND"."XMLTYPETEST_XMLTYPE" 
   (    "ACTIVITYGUID" CHAR(36 BYTE), 
    "XMLDATA" "XMLTYPE"
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" 
 XMLTYPE COLUMN "XMLDATA" STORE AS SECUREFILE BINARY XML (
  TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192
  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES 
  STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) ALLOW NONSCHEMA DISALLOW ANYSCHEMA ;


Name          Type           
------------  -------------- 
ACTIVITYGUID  CHAR(36)       
XMLDATA       PUBLIC.XMLTYPE 

我尝试了各种对象和set*()方法的各种组合来设置XMLData参数以及使用executeUpdate(),所有这些都具有相同的结果:

ORA-01422:精确获取返回的行数超过了请求的行数

如果在库版本中有任何线索,则是相关的依赖项:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>12.2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/oracle/xdb -->
<dependency>
    <groupId>oracle</groupId>
    <artifactId>xdb</artifactId>
    <version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle/xmlparserv2 -->
<dependency>
    <groupId>com.oracle.database.xml</groupId>
    <artifactId>xmlparserv2</artifactId>
    <version>19.3.0.0</version>
</dependency>

谢谢。

java oracle jdbc
1个回答
0
投票

我考虑得越多,库版本不匹配的可疑性就越大。我用以下版本替换了两个库:

        <dependency>
            <groupId>com.oracle.database.xml</groupId>
            <artifactId>xmlparserv2</artifactId>
            <version>12.2.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.oracle.database.xml</groupId>
            <artifactId>xdb6</artifactId>
            <version>12.2.0.1</version>
        </dependency>

解决了问题。 / facepalm

© www.soinside.com 2019 - 2024. All rights reserved.