I have a situation where I need to make Clob object from String. The problem is I can't have ConnectionManager in that method.
I need to some utility like
public Clob getClob(String data){
}
Can any one tell me how can I make this.
I have oralce.sql.CLOB also. however it requires Connection to create object.
To convert CLOB data type to string Reader r = clob. getCharacterStream(); Read each character one by one from the retrieved Stream of characters and append them to the StringBuilder or StringBuffer.
The code you submitted in your question should become: String sql = "select id, data from mytable"; List< Object[] > results = getEntityManager(). createNativeQuery(sql). getResultList(); Map< Long, String > map = new HashMap<>(); Clob clob = (Clob)result[1]; String value = clob.
A CLOB (character large object) value can be up to 2,147,483,647 characters long. A CLOB is used to store unicode character-based data, such as large documents in any character set.
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());
In order to initialize the OracleConnection mentioned in the other answers here and if you're doing this for a java stored procedure and the connection is to the database where the procedure is stored, then the Connection can be initialized like this:
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
and this import is needed:
import oracle.jdbc.driver.OracleConnection;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With