java - 如何解决 Oracle 中的 setString max 32766 字符问题?

标签 java string oracle spring

我使用java和spring在Oracle数据库中写入数据。 代码如下:

org.springframework.jdbc.core.support.JdbcDaoSupport.getJdbcTemplate.
update(String sql, Object[] args) ;

所有参数都是字符串。有时我会收到错误:

 java.sql.SQLException: setString can only process strings of 
less than 32766 chararacters

遇到这种情况我能做什么? 谢谢。

最佳答案

我有一个例子,sql是:

CREATE TABLE t_customer (
id         LONG         NOT NULL,
first_name VARCHAR2(32) NOT NULL,
last_name  VARCHAR2(32) NOT NULL,
last_login TIMESTAMP    NOT NULL,
comments   CLOB         NOT NULL
)

配置如下:

<bean id="nativeJdbcExtractor"
       class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/>
<bean id="lobHandler"
      class="org.springframework.jdbc.support.lob.OracleLobHandler">
    <property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
</bean>

代码:

private void runInTemplate() {
    this.jdbcTemplate.update(
            "insert into t_customer " +
                    "(id, first_name, last_name, last_login, comments) " +
                    "values (?, ?, ?, ?, ?)",
            new PreparedStatementSetter() {
                public void setValues(PreparedStatement ps)
                        throws SQLException {
                    ps.setLong(1, 2L);
                    ps.setString(2, "Jan");
                    ps.setString(3, "Machacek");
                    ps.setTimestamp(4,
                            new Timestamp(System.currentTimeMillis()));
                    lobHandler.getLobCreator().setClobAsString(ps, 5,
                            "This is a loooong String!");
                }
            });
}

关于java - 如何解决 Oracle 中的 setString max 32766 字符问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13842434/

相关文章:

java - 图像上弹出文本的 CSS 帮助

链表中的Java算法

c# - 输入字符串的格式不正确

c - Oracle OCI 触发器创建

java - Android:ExpandableListView 和上下文菜单

c++ mysql查询字符串用引号和变量解析

string - 评估字符串中的 boolean 表达式 - Go

sql - Oracle SQLPlus : How to display the output of a sqlplus command without having to first issue the spool off command?

sql - Oracle SQL 按级别连接

Java泛型编译错误: incompatible types: Item#1 cannot be converted to Item#2