String s1="1234abc我是大字段CLOB或BOLB";
//String 轉 clob
Clob c = new SerialClob(s1.toCharArray());
//String 轉 blob
Blob b = new SerialBlob(s1.getBytes("GBK"));
//也可以這樣不傳字符集名稱,使用系統默認的
//Blob b = new SerialBlob(s1.getBytes());
//clob 轉 String
String clobStri = c.getSubString(1, (int) c.length());
//blob 轉 String
String blobString = new String(b.getBytes(1, (int) b.length()),"GBK");
//前面若沒傳入字符集名稱,則這里也不需要傳入,以免出錯
//String blobString = new String(b.getBytes(1, (int) b.length()));
System.out.println(clobString);
System.out.println(blobString);
public static String convertToString(Object o){if(o == null)return null;if(o instanceof String){return (String)o;}else if(o instanceof Integer){return o.toString();}else if(o instanceof SerializableClob){SerializableClob clob = (SerializableClob) o ;try {return clob.getSubString(1, (int) clob.length());} catch (SQLException e) {throw new RuntimeException(e);}}return o.toString();}
這種數據庫的字段類型轉成Java字段類型的行為,從框架上來說叫做orm(object-relative-model)對象關系模型
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态