简体   繁体   English

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

[英]Why would I get ORA-01422 error while inserting a single row using JDBC

I see many related questions about this particular error - most of them having to do with SELECT INTO operations.我看到许多有关此特定错误的相关问题 - 其中大多数与SELECT INTO操作有关。

In this case though, I'm trying to insert a single row and don't find any answers to this particular issue.不过,在这种情况下,我试图插入一行,但没有找到这个特定问题的任何答案。

I'm using the following code:我正在使用以下代码:

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();
}

The table XMLTYPETEST_XMLTYPE is defined as follows:表 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 

I've tried various combinations of objects and set*() methods for setting the XMLData parameter as well as using executeUpdate() , all with the same result:我尝试了各种对象组合和set*()方法来设置 XMLData 参数以及使用executeUpdate() ,结果都相同:

ORA-01422: exact fetch returns more than requested number of rows ORA-01422: 精确提取返回的行数多于请求的行数

In case there's any clue in the library versions, here are the relevant dependencies:如果库版本中有任何线索,这里是相关的依赖项:

<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>

Thanks.谢谢。

The more I thought about it, the more suspicious the mismatched library versions were.我想得越多,不匹配的库版本就越可疑。 I replaced two libraries with the following versions:我用以下版本替换了两个库:

        <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>

That fixed the problem.这解决了问题。 /facepalm /掌脸

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM