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);
String s1="1231dsdgasd的飒飒大";Clob c = new SerialClob(s1.toCharArray());//String 转 clobBlob b = new SerialBlob(s1.getBytes("GBK"));//String 转 blob//也可以这样不传字符集名称,默认使用系统的//Blob b = new SerialBlob(s1.
需要把
String
类型
数据
转换成
Reader,然后再使用setCharacterStream插入数据库中。
例如下例中,要插入
String
longStr,则先
转换成
Byte[],再ByteArrayInputStream,最后InputStreamReader。
添加或更新clob型数据,如下所示(以更新为例):
PreparedStatement pstmt=conn.prepar
这里写目录标题将
String
字符串
转换成
Blob
对象将TypeArray
转换成
Blob
对象ArrayBuffer转
Blob
将
Blob
对象
转换成
String
字符串将
Blob
对象
转换成
ArrayBuffer
将
String
字符串
转换成
Blob
对象
//将字符串
转换成
Blob
对象
var
blob
= new
Blob
(["Hello World!"], {
type: 'text/plain'
console.info(
blob
);
console.info(
blob
.slice(
public
String
clobTo
String
(Clob clob) throws Exception {
String
re = "";
Reader is = null;
BufferedReader br = null;
try {
// 得到流
is = clob.getCharacterStream();
br = new BufferedReader(is);
//
blob
内存放的是字节数组
//
String
的getBytes方法获得该字符串的字节数组(注意编码),然后存入
blob
即可
String
blob
Str = "
blob
";
byte[] bytes;
try {
bytes =
blob
Str.getBytes("utf-8");
System.out.println("===" + bytes);
found [text (Types#LONGVARCHAR)], but expecting [varchar(255) (Types#VARCHAR)] 或 found [
blob
(Types#LONGVARBINARY)], but expecting [tiny
blob
(Types#VARBINARY)]
数据库中字段使用
blob
时
Java
中使用byte[] 接收
blob
时,会报如下错误
found [
blob
(Types#LONGVARBINARY)], but expecting [
1.定义:
SQL:alter table
blob
_test ADD column `new_data`
BLOB
DEFAULT NULL COMMENT '新数据' after id;
java
: private byte[] newData;
2.存储:
字符串转byte :