写入Oracle Blob字段
/**
* 插入Blob字段
*/
public static void insertBlobField(){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
String url = "jdbc:oracle:thin:@192.168.8.100:1521:ORCL";
String username = "shouyao";
String password = "shouyao";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.execute("insert into a_blob_test(id,picture) values(1,empty_blob())");
rs = stmt.executeQuery("select t.id,t.picture from a_blob_test t where t.id = 1 for update");
File f1 = new File("E:\\hel\\MyEclipse 10.0\\druggist\\code\\src\\test\\test.jpg");
FileInputStream fis = new FileInputStream(f1);
OutputStream os = null;
if(rs.next()){
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(2);
os = blob.getBinaryOutputStream();
byte[] b = new byte[(int) f1.length()];
fis.read(b);
os.write(b);
os.flush();
}
os.close();
conn.commit();
rs.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(stmt != null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
读取oracle Blob字段
/**
* 查询Blob字段存储的图片文件,并输出
*/
public static void queryBlobField(){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String url = "jdbc:oracle:thin:@192.168.8.100:1521:ORCL";
String username = "shouyao";
String password = "shouyao";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
rs = stmt.executeQuery("select t.id,t.picture from a_blob_test t where t.id = 1");
//文件保存的路径
File f1 = new File("E:\\hel\\MyEclipse 10.0\\druggist\\code\\src\\test\\test1.jpg");
FileOutputStream fos = new FileOutputStream(f1);
InputStream is = null;
if(rs.next()){
Blob blob = rs.getBlob(2);
is = blob.getBinaryStream();
int len =0;
byte[] b = new byte[1024];
while((len = is.read(b)) != -1){
fos.write(b,0,len);
}
}
fos.close();
is.close();
rs.close();
stmt.close();
conn.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
if(stmt != null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
分享到:
相关推荐
jdbc 操作oracle blob数据jdbc 操作oracle blob数据jdbc 操作oracle blob数据jdbc 操作oracle blob数据jdbc 操作oracle blob数据jdbc 操作oracle blob数据jdbc 操作oracle blob数据jdbc 操作oracle blob数据jdbc ...
很多朋友在操作oracle数据库的clob,blob字段时不知道怎么插入和使用,这里提供读写范例。
C#访问oracle数据库类 1、执行非查询命令 2、执行查询命令 3、带blob字段读写
Oracle blob字段上传下载 Oracle blob字段上传下载Oracle blob字段上传下载 Oracle blob字段上传下载
delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段delphi读写BLOB字段...
oracle中对blob字段的处理方法,包括增加,删除,修改,更新等操作。
JDBC读写Oracle的CLOB字段
oracle查询blob字段照片(jpeg) 像素大小sql
java中读取ORACLE中BLOB字段存储的图片
只需要安装oracle client在本地,然后配置好tns,输入连接名,用户名,密码,数据表的名称,文件名数据列名以及blob数据列名,就可以批量导出ORACLE数据库BLOB字段生成图片
该程序可将ORACLE中BLOB字段导入到SQL SERVER中的IMAGE字段,方便快捷。
oracle中用来存储大数据的BLOB(图片,文本,文件等)的 读写与复制方法
oracle中使用jdbc读写clob字段,很多细节介绍,内容全面。
Python如何操作Oracle的Blob字段,
基于JSP访问ORACLE数据库BLOB字段并显示图形的解决方案.pdf
JDBC操纵Oracle数据库中的BLOB字段
JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等...
有关Oracle对blob字段的操作读取方法,里面有详细的例子
主要介绍了使用JDBC4.0操作Oracle中BLOB类型数据的方法,我们需要使用ojdbc6.jar包,本文介绍的非常详细,需要的朋友可以参考下
java对oracle数据库中blob字段的处理