oracle中blob和clob文件上传
来源:互联网 发布:qq空间psd源码下载 编辑:程序博客网 时间:2024/04/29 19:22
其中数据库连接使用的是前一篇文章jdbc连接oracle代码。
public void uploadBlobFile() throws SQLException, IOException {
DbConn dbc = new DbConn();
Connection conn = dbc.getconn();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
st.executeUpdate("insert into blob_test values(133,empty_blob())");
ResultSet rs = st.executeQuery("select file_contet from blob_test where id=133 for update");
if (rs.next()) {
// 得到java.sql.Blob对象,然后Cast为oracle.sql.BLOB
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
// 到数据库的输出流
OutputStream outStream = blob.getBinaryOutputStream();
// 这里用一个文件模拟输入流
InputStream in = new FileInputStream(new File("D://工作文档.doc"));
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ((len = in.read(b)) != -1) {
outStream.write(b, 0, len);
}
in.close();
}
conn.commit();
rs.close();
st.close();
conn.close();
}
public void downBlobFile() throws SQLException, IOException {
DbConn dbc = new DbConn();
Connection conn = dbc.getconn();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
conn.commit();
ResultSet rs = st.executeQuery(
"select file_contet from blob_test where id=123 ");
if (rs.next()) {
java.sql.Blob blob = rs.getBlob(1);
InputStream ins = blob.getBinaryStream();
// 用文件模拟输出流
File file = new File("d://output.doc");
OutputStream fout = new FileOutputStream(file);
// 下面将BLOB数据写入文件
byte[] b = new byte[1024];
int len = 0;
while ((len = ins.read(b)) != -1) {
fout.write(b, 0, len);
}
// 依次关闭
fout.close();
ins.close();
}
conn.commit();
conn.close();
}
public void uploadClobFile() throws SQLException, IOException {
DbConn dbc = new DbConn();
Connection conn = dbc.getconn();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
st.executeUpdate("insert into clob_test values(133,empty_clob())");
ResultSet rs = st
.executeQuery("select file_contet from clob_test where id=133 for update");
if (rs.next()) {
// 得到java.sql.Clob对象,然后Cast为oracle.sql.CLOB
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob(1);
// 到数据库的输出流
Writer outStream = clob.getCharacterOutputStream();
// 这里用一个文件模拟输入流
Reader in = new FileReader(new File("D://工作文档.doc"));
char[] b = new char[clob.getBufferSize()];
int len = 0;
while ((len = in.read(b)) != -1) {
outStream.write(b, 0, len);
}
in.close();
}
conn.commit();
rs.close();
st.close();
conn.close();
}
public void downClobFile() throws SQLException, IOException {
DbConn dbc = new DbConn();
Connection conn = dbc.getconn();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
conn.commit();
ResultSet rs = st.executeQuery(
"select file_contet from clob_test where id=133 ");
if (rs.next()) {
java.sql.Clob clob = rs.getClob(1);
InputStream ins = clob.getAsciiStream();
// 用文件模拟输出流
File file = new File("d://output2.doc");
OutputStream fout = new FileOutputStream(file);
// 下面将BLOB数据写入文件
byte[] b = new byte[1024];
int len = 0;
while ((len = ins.read(b)) != -1) {
fout.write(b, 0, len);
}
// 依次关闭
fout.close();
ins.close();
}
conn.commit();
conn.close();
}
- oracle中blob和clob文件上传
- Oracle中Blob和Clob
- Oracle中Blob和Clob的作用
- Oracle中Blob和Clob的作用
- Oracle中Blob和Clob的作用?
- oracle中BLOB和CLOB的区别
- java读取oracle中Clob和Blob
- Oracle中 CLOB, BLOB和NLOB
- Oracle中的BLOB和CLOB
- Oracle中的BLOB和CLOB
- Oracle中的Clob和Blob
- Oracle中的BLOB和CLOB
- Oracle中的BLOB和CLOB
- Oracle中BLOB和CLOB字段的操作
- oracle中导出和导入部分blob,clob字段
- Oracle中BLOB和CLOB数据的读写
- oracle中Blob和Clob类型的区别!
- oracle中Blob和Clob类型的区别
- 07.12.25-09.12.24从这个格式中取后面的日期
- 肥姐沈殿霞离世追悼会时间待定 为女儿留下上亿遗产
- 4-Oracle积累
- newusers和chpasswd的用法(批量)
- grilview属性 事件
- oracle中blob和clob文件上传
- 服装企业信息化面临三大瓶颈
- 70后、80后、90后:一代不“如”一代
- 阿里巴巴2008年创纪录狂招2000多销售人才
- 文字分散对齐的方法
- 阿里巴巴今年要招3000人 提供多个职位
- 面向.NET开发人员的Ajax 技术平台策略
- Log4j简介
- 调查显示企业IT技术员工面临短缺