Using CLOB in java throwing exception

I am inserting clob data into mysql database ... here is my code

Clob cl=dbCon.createClob();
cl.setString(1,userAbout);
dbCon.setAutoCommit(false);
PreparedStatement insertClob=dbCon.prepareStatement("UPDATE user_data SET user_about=? WHERE user_id=?");
insertClob.setClob(1,cl);
insertClob.setInt(2,userId);
int count= insertClob.executeUpdate();
if(count==1){dbCon.commit();dbCon.close();out.write("success");}
else{dbCon.rollback();dbCon.close();out.print("error");}

it throws an exception

java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.createClob()Ljava/sql/Clob;

What is the problem? and how can i solve it?

+1
source share
1 answer

In any case, you do not need createClob(). I believe that using setCharacterStream () will be much more stable (and much better supported by all JDBC drivers).

StringReader reader = new StringReader(userAbout);
PreparedStatement insertClob = dbCon.prepareStatement("UPDATE user_data SET user_about=? WHERE user_id=?");
insertClob.setCharacterStream(1, reader, userAbout.length());
insertClob.setInt(2,userId);

int count= insertClob.executeUpdate();

This also works with the operator INSERT. There is no need to create any intermediate clob (or blob) objects.

Please note that I changed the wrong index 8to the correct index 2to match placeholders in the statement UPDATE.

"" setString(), CLOB. - .

+5

Source: https://habr.com/ru/post/1529623/


All Articles