我正在 Oracle 数据库中编写一个 Java 函数,它生成大量文本! 如何在 java 中将字符串转换为 CLOB (oracle.sql.CLOB)? 什么是最直接的方法?
我正在尝试构建一个以 String 作为输入、以 oracle.sql.CLOB 作为输出的函数,但它不起作用!我没有做任何jdbc相关的工作!
这是我所拥有的(它不起作用!)
public static CLOB str2clob(String s)
{
oracle.sql.CLOB clob = null;
try
{
clob.setString(0,s);
} catch (Exception e)
{
}
return clob;
}
最佳答案
/*********************************************************************************************
* From String to CLOB
* @return CLOB representation of string
*********************************************************************************************/
private java.sql.Clob stringToClob(String source)
{
try
{
return new javax.sql.rowset.serial.SerialClob(source.toCharArray());
}
catch (Exception e)
{
log.error("Could not convert string to a CLOB",e);
return null;
}
}
关于java - 在 java 中将字符串转换为 oracle.sql.clob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8066018/