Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String to CLOB with postgreSQL

I'm trying to read a clob from postgreSQL DB, change it, and write it back.

I was able to read the clob successfully using the following code:

PreparedStatement statement = connection.prepareStatement("SELECT clob_column from data where id = 1");
ResultSet executeQuery = statement.executeQuery();
executeQuery.next()
Clob fetchedClob = executeQuery.getClob("clob_column");

But when I'm trying to create a new clob with the new data using:

Clob newClob = connection.createClob();

I'm getting the following error:

java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyConnection.createClob()Ljava/sql/Clob;  

Moreover, If I try just to edit the fetched clob, using:

fetchedClob.setString(0, "new string");

I'm getting the following error:

Method org.postgresql.jdbc4.Jdbc4Clob.setString(long,str) is not yet implemented.

Any idea?

Update: here is the table definition

CREATE TABLE data ( id bigint NOT NULL, clob_column text, );

Thanks

like image 692
Ben Bracha Avatar asked Aug 27 '12 10:08

Ben Bracha


1 Answers

No need to use getClob().

ResultSet.getString() and setString() work perfectly fine on text columns (PostgreSQL does not have a clob datatype so I assume you are using text)

like image 151
a_horse_with_no_name Avatar answered Nov 15 '22 18:11

a_horse_with_no_name