Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the clob value from the resultList of jpa native query?

I execute a native query by JPA. My DB is oracle and I have a Clob column. When I get the result, How can I get the clob value from the resultList? I cast it to String and I get ClassCastException. actual object is com.sun.proxy.$Proxy86.

Query query = entityManager.createNativeQuery("Select Value from Condition");
List<Object[]> objectArray =  query.getResultList();
for (Object[] object : objectArray) {
     ???
}
like image 692
Hamid Avatar asked Dec 10 '22 07:12

Hamid


1 Answers

You can use java.sql.Clob

for (Object[] object : objectArray) {
       Clob clob = (Clob)object[0];
       String value = clob.getSubString(1, (int) clob.length());
}
like image 83
Ram Avatar answered Jan 12 '23 14:01

Ram