易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle中BLOB/CLOB字段可能遇到的问题

Blob 采用单字节存储,适合保存二进制数据,如图片、视频等。
Clob 采用多字节存储,适合保存大型文本数据。
1. 在Oracle JDBC中采用流机制对 BLOB/CLOB 进行读写操作,所以要注意不能在批处理中读写 BLOB/CLOB字段,否则将出现
Stream type cannot be used in batching 异常。
2. Oracle BLOB/CLOB 字段本身拥有一个游标(cursor),JDBC通过游标对Blob/Clob字段进行操作,在Blob/Clob字段创建之前,无法获取其游标句柄,会出现
Connection reset by peer: socket write error 异常。
正确的做法是:首先创建一个空 Blob/Clob 字段,再从这个空 Blob/Clob字段获取游标,例如下面的代码:
PreparedStatement ps  =  conn.prepareStatement( " insert into PICTURE(image,resume) values(?,?) " );
//  通过oralce.sql.BLOB/CLOB.empty_lob()构造空Blob/Clob对象
ps.setBlob( 1 ,oracle.sql.BLOB.empty_lob());
ps.setClob( 2 ,oracle.sql.CLOB.empty_lob());
ps.excuteUpdate();
ps.close();
//  再次对读出Blob/Clob句柄
ps  =  conn.prepareStatement( " select image,resume from PICTURE where id=? for update " );
ps.setInt( 1 , 100 );
ResultSet rs  =  ps.executeQuery();
rs.next();
oracle.sql.BLOB imgBlob  =  (oracle.sql.BLOB)rs.getBlob( 1 );
oracle.sql.CLOB resClob  =  (oracle.sql.CLOB)rs.getClob( 2 );
//  将二进制数据写入Blob
FileInputStream inStream  =   new  FileInputStream( " c://image.jpg " );
OutputStream outStream  =  imgBlob.getBinaryOutputStream();
byte [] buf  =   new   byte [ 10240 ];
int  len;
while (len = inStream.read(buf) > 0 ) {
 outStream.write(buf, 0 ,len);
}
inStream.close();
outStream.cloese();
//  将字符串写入Clob
resClob.putString( 1 , " this is a clob " );
//  再将Blob/Clob字段更新到数据库
ps  =  conn.prepareStatement( " update PICTURE set image=? and resume=? where id=? " );
ps.setBlob( 1 ,imgBlob);
ps.setClob( 2 ,resClob);
ps.setInt( 3 , 100 );
ps.executeUpdate();
ps.close();
参考资料:开发者在线http://www.builder.com.cn/files/list-0-0-50259-1-1.


相关文档:

oracle wait event:cursor: pin S wait on X

oracle wait event:cursor: pin S wait on X
cursor: pin S wait on X等待事件的处理过程
http://database.ctocio.com.cn/tips/114/8263614_1.shtml
cursor: pin S wait on X等待!
http://www.itpub.net/viewthread.php?tid=1003340
解决cursor: pin S wait on X 有什么好办法:
http://www.itpub.net/thread-1163543 ......

oracle截取字符串的函数substr

语法:
substr( string, start_position, [ length ] )
取子字符串,从start_position开始,取length个,length为可选,如果length为空则返回start_position后的所有字符。
实例:
    substr('This is a test', 6, 2)          would return 'is'
 &nbs ......

oracle基本操作

describe  TABLE_NAME;   --描述
----------------------------------------------------------------
create table as select XXXXXX
insert into TABLE_NAME (reac_1,reac_2.....) values(v1,v2)
insert into TABLE_NAME (select * from ..........)
update TABLE_NAME set reac_1=v1,.............. ......

ORACLE JOB 汇总

一。job的运行频率设置
1.每天固定时间运行,比如早上8:10分钟:Trunc(Sysdate+1) + (8*60+10)/24*60
2.Toad中提供的:
每天:trunc(sysdate+1)
每周:trunc(sysdate+7)
每月:trunc(sysdate+30)
每个星期日:next_day(trunc(sysdate),'SUNDAY')
每天6点:trunc(sysdate+1)+6/24
半个小时:sysdate+30/1440
3.每个 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号