在Oracle数据库中插入Blob

时间:2018-07-16 12:53:34

标签: java oracle

当我试图在数据库中插入超过4000个字符的blob时,我遇到了错误提示:有人可以对此提供帮助吗?除了插入数据的过程以外,还有其他方法吗?

错误报告-

  SQL Error: ORA-01704: string literal too long
  01704. 00000 -  "string literal too long"
  *Cause:    The string literal is longer than 4000 characters.
  *Action:   Use a string literal of at most 4000 characters.
           Longer values may only be entered using bind variables

1 个答案:

答案 0 :(得分:0)

例如,使用setString代替setCharacterStream。 当然,假设您已经在使用PreparedStatement:

try (PreparedStatement stmt = conn.prepareStatement(someSql)) {
    String large = String.format("%-4001s", "xxx");
    StringReader reader = new StringReader(large);
    stmt.setCharacterStream(1, reader, large.length());
    stmt.setLong(2, someId);
    int updateCount = stmt.executeUpdate();
}