Convert String to Clob in Java

I have a situation where I need to make a Clob object from String. The problem is that I cannot have a ConnectionManager in this method.

I need some kind of utility like

 public Clob getClob(String data){

 }

Can anyone tell me how I can do this.

I also have org. however, to create an object, Connection is required.

+5
source share
3 answers

Try the following:

OracleConnection conn;  // initialize this first

CLOB clob = conn.createClob();

public Clob getClob(String data){

    return clob.setString(position, data);
}
+5
source

Throws a warning: Clob is not initialized.

To create Clob, you will need OracleConnection 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);
}
+9
source

Those still looking for an alternative answer, a Clob object can be created without the need for a connection object, as shown below.

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

All Articles