当前位置: 技术问答>java相关
请问oracle的clob字段可不可以存富文本的文件,like .doc .rtf?如果可以如何用java读取?
来源: 互联网 发布时间:2015-07-02
本文导语: 请问oracle的clob字段可不可以存富文本的文件,like .doc .rtf ? 如果可以如何用java读取? | http://www.csdn.net/Expert/TopicView.asp?id=83096&datebasetype=200101 --------------- shmilu@sina.com | 我现...
请问oracle的clob字段可不可以存富文本的文件,like .doc .rtf ?
如果可以如何用java读取?
如果可以如何用java读取?
|
http://www.csdn.net/Expert/TopicView.asp?id=83096&datebasetype=200101
---------------
shmilu@sina.com
---------------
shmilu@sina.com
|
我现在贴上一个读、和写的ORACLE的存取过程
create procedure sp_eml_read_content_html (in_row_id IN String,offset in integer, buf out String)
AS
clob_locator CLOB;
total_amount INTEGER;
read_offset INTEGER := offset;
buffer VARCHAR2(2048);
error_msg VARCHAR2(255);
BEGIN
SELECT html INTO clob_locator FROM eml_message_content
WHERE message_id = in_row_id;
--DBMS_OUTPUT.PUT_LINE('1');
total_amount := 1024; --DBMS_LOB.GETLENGTH(clob_locator);
DBMS_OUTPUT.PUT_LINE('2:'||to_char(total_amount));
DBMS_LOB.READ(clob_locator, total_amount, read_offset, buffer);
buf:=substr(buffer,1,total_amount);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
error_msg := 'no more data';
DBMS_OUTPUT.PUT_LINE(error_msg);
WHEN OTHERS THEN
--error_msg := 'unspecified error occured';
error_msg := sqlerrm(sqlcode);
DBMS_OUTPUT.PUT_LINE(error_msg);
END;
/
create procedure sp_eml_save_content_html(id in String,html in varchar2,offset in integer)
as
html_locator_var clob;
amount_var integer;
offset_var integer;
html_buffer_var varchar(2048);
begin
amount_var:=length(html);
offset_var:=offset;
html_buffer_var:=html;
select html into html_locator_var from eml_message_content where message_id=id for update;
DBMS_LOB.WRITE(html_locator_var,amount_var,offset_var,substr(html_buffer_var,1,amount_var));
commit;
end;
/
用JDBC调用存储过程。就行,注意长度和每次读取的缓冲
create procedure sp_eml_read_content_html (in_row_id IN String,offset in integer, buf out String)
AS
clob_locator CLOB;
total_amount INTEGER;
read_offset INTEGER := offset;
buffer VARCHAR2(2048);
error_msg VARCHAR2(255);
BEGIN
SELECT html INTO clob_locator FROM eml_message_content
WHERE message_id = in_row_id;
--DBMS_OUTPUT.PUT_LINE('1');
total_amount := 1024; --DBMS_LOB.GETLENGTH(clob_locator);
DBMS_OUTPUT.PUT_LINE('2:'||to_char(total_amount));
DBMS_LOB.READ(clob_locator, total_amount, read_offset, buffer);
buf:=substr(buffer,1,total_amount);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
error_msg := 'no more data';
DBMS_OUTPUT.PUT_LINE(error_msg);
WHEN OTHERS THEN
--error_msg := 'unspecified error occured';
error_msg := sqlerrm(sqlcode);
DBMS_OUTPUT.PUT_LINE(error_msg);
END;
/
create procedure sp_eml_save_content_html(id in String,html in varchar2,offset in integer)
as
html_locator_var clob;
amount_var integer;
offset_var integer;
html_buffer_var varchar(2048);
begin
amount_var:=length(html);
offset_var:=offset;
html_buffer_var:=html;
select html into html_locator_var from eml_message_content where message_id=id for update;
DBMS_LOB.WRITE(html_locator_var,amount_var,offset_var,substr(html_buffer_var,1,amount_var));
commit;
end;
/
用JDBC调用存储过程。就行,注意长度和每次读取的缓冲
|
读:
String content ="";
clob = rs.getCLOB(2);
Reader instream = clob.getCharacterStream();
BufferedReader br = new BufferedReader(instream);
while ((str = br.readLine()) != null) {
content = content + str ;
}
String content ="";
clob = rs.getCLOB(2);
Reader instream = clob.getCharacterStream();
BufferedReader br = new BufferedReader(instream);
while ((str = br.readLine()) != null) {
content = content + str ;
}
|
那不是文本文件,那种格式比较难读,方法是有的,继续努力!
|
啊,刚才还应在str后面加一个"n",^_^