String s1="1231dsdgasd的飒飒大";
Clob c = new SerialClob(s1.toCharArray());//String 转 clob
Blob b = new SerialBlob(s1.getBytes("GBK"));//String 转 blob
//也可以这样不传字符集名称,默认使用系统的
//Blob b = new SerialBlob(s1.getBytes());
String clobString = c.getSubString(1, (int) c.length());//clob 转 String
String blobString = new String(b.getBytes(1, (int) b.length()),"GBK");//blob 转 String
//前面若没传入字符集名称,则这里也不需要传入,以免出错
//String blobString = new String(b.getBytes(1, (int) b.length()));
System.out.println(clobString);
System.out.println(blobString);
Java Blob类型和String类型相互转换
最新推荐文章于 2025-02-27 15:41:58 发布
本文提供了一个简单的示例,演示了如何在Java中将字符串转换为CLOB和BLOB类型,同时也展示了如何从CLOB和BLOB类型的数据中提取字符串。这对于在数据库操作中涉及到大文本或二进制数据的读写非常有用。

967

被折叠的 条评论
为什么被折叠?



