java 文件写入oracle数据库blob字段
来源:互联网 发布:apache 官网下载64位 编辑:程序博客网 时间:2024/04/30 02:12
public void file2blob() throws Exception {
String filePath = "D://FILE//t.txt";
oracle.sql.BLOB b = null;
Connection con = null;
Statement st = null;
try {
String uuid = UUID.randomUUID().toString().replace("-", "");
DataSource ds = jdbcT.getDataSource();
con = jdbcT.getDataSource().getConnection();
st = con.createStatement();
st.executeUpdate("INSERT INTO T_BOLB_TEST (OBJ_ID,B_BLOB)VALUES('"
+ uuid + "',EMPTY_blob())");
ResultSet rs = st
.executeQuery("select B_BLOB from T_BOLB_TEST WHERE OBJ_ID='"
+ uuid + "' for update");
if (rs.next()) {
b = (oracle.sql.BLOB) rs.getBlob(1);
File file = new File(filePath);
FileInputStream fin = new FileInputStream(file);
byte[] temp = new byte[fin.available()];
fin.read(temp);
OutputStream out = b.getBinaryOutputStream();
out.write(temp, 0, temp.length);
out.flush();
out.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (st != null) {
st.close();
}
con.commit();
if (con != null) {
con.close();
}
}
}
String filePath = "D://FILE//t.txt";
oracle.sql.BLOB b = null;
Connection con = null;
Statement st = null;
try {
String uuid = UUID.randomUUID().toString().replace("-", "");
DataSource ds = jdbcT.getDataSource();
con = jdbcT.getDataSource().getConnection();
st = con.createStatement();
st.executeUpdate("INSERT INTO T_BOLB_TEST (OBJ_ID,B_BLOB)VALUES('"
+ uuid + "',EMPTY_blob())");
ResultSet rs = st
.executeQuery("select B_BLOB from T_BOLB_TEST WHERE OBJ_ID='"
+ uuid + "' for update");
if (rs.next()) {
b = (oracle.sql.BLOB) rs.getBlob(1);
File file = new File(filePath);
FileInputStream fin = new FileInputStream(file);
byte[] temp = new byte[fin.available()];
fin.read(temp);
OutputStream out = b.getBinaryOutputStream();
out.write(temp, 0, temp.length);
out.flush();
out.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (st != null) {
st.close();
}
con.commit();
if (con != null) {
con.close();
}
}
}
0 0
- java 文件写入oracle数据库blob字段
- c++写入oracle数据库blob字段,读取blob到本地文件
- c++写入oracle数据库blob字段,读取blob到本地文件
- 设置oracle中的blob字段,将xml文件写入到数据库中
- FME综合应用之一:oracle数据库blob字段写入和写出图片或文件等
- [转贴]Java中操作数据库的Blob字段,将文件写入数据库!!!
- JAVA通过Hibernate将文件写入ORACLE数据的BLOB字段 代码示例
- java读取mysql数据库的blob字段和Oracle数据库的Blob字段的区别【读取properties文件】
- JAVA读取Oracle数据库BLOB字段
- java操作oracle数据库中的blob字段
- JAVA读取Oracle数据库BLOB字段
- java读取oracle数据库中blob字段
- Java Oracle数据库BLOB字段的存取
- Java, 将文件对像写入BLOB字段
- Oracle数据库BLOB字段操作
- Oracle数据库BLOB字段操作
- Oracle数据库BLOB字段操作
- java向Oracle数据库中插入blob字段数据
- 指针的复习(1)
- POJ 1011 Sticks CODE[VS] 3498 小木棍(DFS+剪枝优化)
- Android studio启动后卡在refreshing gradle project
- Android任务和返回栈完全解析,细数那些你所不知道的细节
- Maven相关知识(一)
- java 文件写入oracle数据库blob字段
- cocos2dx中c++向lua传string的问题
- HDU 4059-容斥原理 +拉格朗日插值法
- Nginx平滑升级
- android的代码规范
- poj3239(深搜)
- Intent使用规范:不要在Intent的中携带待会自动被提交的数据。
- Mysql5.7究竟该如何安装
- centos下安装NS2