This is an example of how to update CLOBs in your applications.
/////////////////////////////////////////
// UpdateClobs is an example application
// that shows some of the APIs providing
// support for changing Clob objects
// and reflecting those changes to the
// database.
//
// This program must be run after
// the PutGetClobs program has completed.
/////////////////////////////////////////
import java.sql.*;
public class UpdateClobs {
public static void main(String[] args)
throws SQLException
{
// Register the native JDBC driver.
try {
Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
} catch (Exception e) {
System.exit(1); // Setup error.
}
Connection c = DriverManager.getConnection("jdbc:db2:*local");
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM CUJOSQL.CLOBTABLE");
rs.next();
Clob clob1 = rs.getClob(1);
rs.next();
Clob clob2 = rs.getClob(1);
// Truncate a CLOB.
clob1.truncate((long) 150000);
System.out.println("Clob1's new length is " + clob1.length());
// Update a portion of the CLOB with a new String value.
String value = "Some new data for once";
int charsWritten = clob2.setString(500L, value);
System.out.println("Characters written is " + charsWritten);
// The bytes can be found at position 500 in clob2
long startInClob2 = clob2.position(value, 1);
System.out.println("pattern found starting at position " + startInClob2);
c.close(); // Connection close also closes stmt and rs.
}
}