The examples that follow will explain how to:
- Inserting and retrieving empty CLOB data.Use
- Retrieve CLOB data using the Ingres JDBC driver.
- Updating existing CLOB data.
Inserting and retrieving empty CLOB data:
conn = getConnection();
prepStmt = conn.prepareStatement("INSERT INTO clob_table VALUES(?,?,?,?)");
prepStmt.setString(1,id);
prepStmt.setString(2,filename);
// Insert empty CLOB data
prepStmt.setString(3, "");
prepStmt.setString(4, "2009-07-10");
prepStmt.execute();
Use various techniques to insert CLOB data:
Clob c = rs.getClob(columnIndex);
InputStream data = c.getAsciiStream();
public static void updateClobAsString(String id, String content) {
Connection conn = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
try {
//Obtains a connection
conn = getConnection();
prepStmt = conn.prepareStatement("UPDATE clob_table SET xmldocument = ? WHERE id='" + id + "'");
prepStmt.setString(1,content);
prepStmt.execute();
}
catch(Exception sqlEx) {
sqlEx.printStackTrace();
}
finally {
DbUtils.closeQuietly(conn, prepStmt, rs);
}
}
Posted in: