将对象转换为CLOB [英] Converting object to CLOB
问题描述
我有一个对象数组(它是Oracle数据库中本机查询的输出),其中的第一个元素是CLOB数据类型,需要转换为Java String对象.我将如何实现呢?请帮忙.
I have a object array( it is an output of a native query in Oracle database) out of which the first element is of CLOB data type which needs to converted to a java String object. How would I achieve this? Please help.
String sql = "select id, data from mytable";
List< Object[] > results = getEntityManager().createNativeQuery(sql).getResultList();
Map< Long, String > map = new HashMap<>();
for (Object[] result : results) {
map.put(((Number) result[0]).longValue(), (String) result[1]);
}
data是mydata表中具有CLOB数据类型的列. result(1)将拥有我的CLOB数据
data is a column in mydata table with CLOB data type. result(1) would have my CLOB data
在放入HashMap时,我需要将result(1)解析为String.
While putting in the HashMap I need to parse the result(1) as String.
推荐答案
作为我的查询的一种解决方案,摆脱了本机查询,改用了休眠模式. 使用javax.persistence.Lob
As a solution to my query, got rid of the native query and used hibernate instead. Mapped my CLOB column with javax.persistence.Lob
@Lob
@Column(name = "DATA")
byte[] clobData
这篇关于将对象转换为CLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!