Guest User

Untitled

a guest
Aug 12th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. How to use setCharacterStream to update Clob in Oracle?
  2. String toBeUpdated = ""
  3. StringReader reader = new StringReader(toBeUpdated);
  4. pStmt.setCharacterStream(parameterIndex,reader , toBeUpdated.length());
  5.  
  6. long id = ...
  7. String content = ... // CLOB content
  8. try {
  9. Class.forName ("oracle.jdbc.OracleDriver");
  10. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@MY_SERVER:1521:MY_DB", "user", "pass");
  11. String query = "UPDATE MY_TABLE SET MY_CLOB_COLUMN = ? WHERE ID = ? ";
  12. OraclePreparedStatement opstmt = (OraclePreparedStatement)conn.prepareStatement(query);
  13. opstmt.setStringForClob(1, content);
  14. opstmt.setLong(2, id);
  15. int result = opstmt.executeUpdate();
  16. System.out.println("Resultado para : " + tabla + " - " + columna + " - " + id + ":" + result);
  17. } catch (SQLException ex) {
  18. //Log here
  19. } catch (ClassNotFoundException ex) {
  20. //Log here
  21. }
Add Comment
Please, Sign In to add comment