CLOB Examples Using JDBC


The examples that follow will explain how to:
  1. Inserting and retrieving empty CLOB data.Use 
  2. Retrieve CLOB data using the Ingres JDBC driver.
  3. 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();

Updating existing CLOB data:

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);
     }
  }


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email