JAVA Clob问题
javaClob类中有没有类似于Blob类这样的方法Blobblob=rs.getBlob();blob.getBytes(1L,(int)blob.length());...
java Clob类中有没有类似于Blob类 这样的方法 Blob blob = rs.getBlob();
blob.getBytes(1L, (int)blob.length()); 最主要是这句blob.getBytes(1L, (int)blob.length()); 最后返回一个字节数组。Clob中该怎么返回一个Byte[]呢? 展开
blob.getBytes(1L, (int)blob.length()); 最主要是这句blob.getBytes(1L, (int)blob.length()); 最后返回一个字节数组。Clob中该怎么返回一个Byte[]呢? 展开
2个回答
展开全部
看clob的实现类SerialClob得构造你就明白了。
CLOB是存放在一个大数组里面的
public SerialClob(char ch[]) throws SerialException, SQLException {
// %%% JMB. Agreed. Add code here to throw a SQLException if no
// support is available for locatorsUpdateCopy=false
// Serializing locators is not supported.
len = ch.length;
buf = new char[(int)len];
for (int i = 0; i < len ; i++){
buf[i] = ch[i];
}
origLen = len;
}
CLOB是存放在一个大数组里面的
public SerialClob(char ch[]) throws SerialException, SQLException {
// %%% JMB. Agreed. Add code here to throw a SQLException if no
// support is available for locatorsUpdateCopy=false
// Serializing locators is not supported.
len = ch.length;
buf = new char[(int)len];
for (int i = 0; i < len ; i++){
buf[i] = ch[i];
}
origLen = len;
}
追问
能说明一下实现么?谢谢!
追答
具体实现不好说,我给你一个我转换string到clob得例子,希望你能理解
callStmt.setClob(i, new SerialClob(convertStrToClob(data)));
private char[] convertStrToClob(String strData) {
byte[] b = null;
char[] c = new char[60000];
try {
b = strData.getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException e) {
logger.error("Error in getting bytes from data", e);
}
for (int j = 0; j <b.length; j++) {
int k = (int)b[j];
if (k < 0) k += 256;
c[j] = (char)k;
}
return c;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询