Convert String to Clob in Java

Try this :

OracleConnection conn;  // initialize this first

CLOB clob = conn.createClob();

public Clob getClob(String data){

    return clob.setString(position, data);
}

Throws warning: Clob not initialized.

You need an OracleConnection to create a Clob, using the Oracle Database.

OracleConnection conn;  // initialize this first

Clob myClob = conn.createClob();



private OracleConnection conn = null;
public void setConnection( OracleConnection conn )
{
    this.conn = conn;
}

void setClob( String cookie ) throws SQLException
{
    Clob myClob = conn.createClob();
    myClob.setString( 1, cookie);
}

Those who are still looking for an alternate answer, a Clob object could be created without the need for a connection object as shown below.

Clob myClob = new javax.sql.rowset.serial.SerialClob(stringData.toCharArray());