发布网友 发布时间:2022-04-26 23:47
共1个回答
热心网友 时间:2022-06-20 10:05
给你段参考代码,读取clob数据
import java.io.InputStream;
import java.io.Reader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class TestClobOut {
public static void main(String args[]){
String data;
Reader inStream=null;
//获得数据库连接
Connection con = ConnectionFactory.getConnection();//ConnectionFactory类是另外定义的,不必纠结
con.setAutoCommit(false);
Statement st = con.createStatement();
//不需要“for update”
ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1");
if (rs.next())
{
java.sql.Clob clob = rs.getClob("CLOBATTR");
inStream = clob.getCharacterStream();
char[] c = new char[(int) clob.length()];
inStream.read(c);
//data是读出并需要返回的数据,类型是String
data = new String(c);
inStream.close();
}
inStream.close();
con.commit();
con.close();
}
}