简体   繁体   English

无法使用JDBCTemplate插入扩展VARCHAR2

[英]Cannot Insert into Extended VARCHAR2 using JDBCTemplate

The need arose to store in excess of 4000 bytes into VARCHAR2 in Oracle database. 需要将超过4000个字节存储到Oracle数据库的VARCHAR2中。 The workaround was to engage the 'Extended Data Types'on the database to increase capacity. 解决方法是在数据库中使用“扩展数据类型”以增加容量。 I am storing a maximum of 2000 characters but the special characters I'm inserting are up to 3 bytes each. 我最多可存储2000个字符,但是我要插入的特殊字符每个最多3个字节。

http://docs.oracle.com/database/121/SQLRF/sql_elements001.htm#SQLRF55623 http://docs.oracle.com/database/121/SQLRF/sql_elements001.htm#SQLRF55623

Manual insertion using SQLDeveloper or a SQL statement works fine . 使用SQLDeveloper或SQL语句手动插入效果很好 Tested with 2000 characters / 6000 bytes. 测试了2000个字符/ 6000个字节。

However, when attempting to insert any String over 4000 bytes using NamedParameterJdbcTemplate, I receive the following error: 但是,当尝试使用NamedParameterJdbcTemplate插入超过4000字节的任何String时,出现以下错误:

Caused by: java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column 由以下原因引起的:java.sql.SQLException:ORA-01461:只能将LONG值绑定为插入到LONG列中

This leads me to believe that it is a driver issue of some type. 这使我相信这是某种类型的驱动程序问题。 I'm using dependency: 我正在使用依赖项:

    <dependency>
        <groupId>com.oracle.weblogic</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>10.3.6.0</version>
    </dependency>

Code: 码:

@Override
public Number createRecord(Number incidentId, String type, 
String verbatim, String createdBy) {
     MapSqlParameterSource parameters = new MapSqlParameterSource();
     parameters.addValue(MyConstants.MAP_VERBATIM, verbatim);
     namedTemplate.update(insertRecordSql, parameters, key, new 
     String[]{"VERBATIM_ID"});
     return key.getKey();
}

Column definition: 列定义:

"VERBATIM" VARCHAR2(2000 CHAR) NOT NULL ENABLE “ VERBATIM” VARCHAR2(2000 CHAR)不为空

Your maven entry looks strange. 您的Maven条目看起来很奇怪。 You are trying to utilize oracle 12c enhancement but still, you are using jar from oracle 10 <version>10.3.6.0</version> . 您正在尝试利用oracle 12c增强功能,但仍在使用oracle 10 <version>10.3.6.0</version> jar。 Moreover if you jdk is higher than jdk6 you probably you have to use ojdbc7 此外,如果您的jdk高于jdk6,则可能必须使用ojdbc7

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

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