- 浏览: 312621 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
lst923:
...
java 实现图片裁剪 -
kakarottoz:
多谢博主分享,正好用到!
java 实现图片裁剪 -
Vcb:
http://osgi.jxtech.net 是一个完全基于O ...
OSGi介绍 -
Vcb:
是一个完全基于OSGi的开发平台,有在线演示,免费插件可供下 ...
OSGi介绍 -
mikey_5:
谢谢分享,原来设置: style="word-bre ...
td内容自动换行
jdbc 插入、读取oracle blob字段
原文参考:http://blog.csdn.net/zhyuh_perl/article/details/7247324
package com.ssgm.jyu.jdbc; import java.io.*; import java.sql.*; import oracle.sql.*; import oracle.jdbc.*; public class JdbcBlob { public static void main(String[] args){ Connection conn = null; Statement stmt = null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); } catch(ClassNotFoundException e){ e.printStackTrace(); } try{ conn = DriverManager.getConnection("jdbc:oracle:thin:@Host:1521:SID","username","passwd"); stmt = conn.createStatement(); conn.setAutoCommit(false); String sourceDir = "C:\\temp\\"; String targetDir = "C:\\temp\\retrieved\\"; String fileName = "cbr_order_version.dmp"; System.out.println("Writing BLOB to blob_content..."); writeBLOB(stmt,sourceDir+fileName); System.out.println("Reading BLOB from blob_content..."); readBLOB(stmt,fileName,sourceDir,targetDir); } catch(SQLException e){ e.printStackTrace(); } finally{ try{ stmt.close(); conn.close(); } catch(SQLException e){ e.printStackTrace(); } } } public static void writeBLOB(Statement stmt, String fullName){ ResultSet blobRS = null; try{ String sqlInsert = "INSERT INTO blob_content VALUES ('"+fullName+"',EMPTY_BLOB())"; String sqlSelect = "SELECT blob_column FROM blob_content WHERE file_name='"+fullName+"' FOR UPDATE"; //step1: initialize the LOB column to set the LOB locator stmt.executeUpdate(sqlInsert); //step2: retrieve the row containing the LOB locator blobRS = stmt.executeQuery(sqlSelect); blobRS.next(); //step3: create a LOB obj and read the LOB locator BLOB myBlob = ((OracleResultSet) blobRS).getBLOB("blob_column"); //step4: get the chunksize of the LOB from the LOB object int chunkSize = myBlob.getChunkSize(); //step5: create a buffer to hold a block of data from the file byte[] byteBuffer = new byte[chunkSize]; //step6: create a file obj to open the file File file = new File(fullName); //step7: create an input stream obj to read the file contents FileInputStream in = new FileInputStream(file); //step8: read the file contents and write it to the LOB long position = 1; int bytesRead; while((bytesRead = in.read(byteBuffer)) != -1){ //write the buffer contents to myBlob myBlob.setBytes(position, byteBuffer); position += bytesRead; } //step9: commit stmt.execute("COMMIT"); //step10: close the objects used to read the file in.close(); blobRS.close(); System.out.println("Wrote content from "+fullName+" to BLOB\n"); } catch(SQLException e){ System.out.println("Error Code: "+e.getErrorCode()); System.out.println("Error Message: "+e.getMessage()); e.printStackTrace(); } catch(IOException e){ System.out.println("Error Message: "+e.getMessage()); e.printStackTrace(); } } public static void readBLOB( Statement stmt, String fileName, String sourceDir, String targetDir){ String sqlSelect = "SELECT blob_column FROM blob_content WHERE file_name='"+ sourceDir+fileName+"'"; ResultSet blobRS = null; try{ //step1: retrieve the row containing the BLOB locator blobRS = stmt.executeQuery(sqlSelect); blobRS.next(); //step2: create a LOB obj and read the LOB locator BLOB myBlob = ((OracleResultSet) blobRS).getBLOB("blob_column"); //step3: get the chunk size of the LOB from the LOB obj int chunkSize = myBlob.getChunkSize(); //setp4: create a buffer to hold a chunk of data from LOB byte[] byteBuffer = new byte[chunkSize]; //step5: create a file obj String saveFile = targetDir + "retrievedBLOB"+fileName; File file = new File(saveFile); //step6: create output stream obj to write the LOB contents FileOutputStream out = new FileOutputStream(file); //step7: get the long of LOB contents long blobLength = myBlob.length(); //step8: read a chunk of data from myBlob, //then write the buffer contents to file for (long position=1; position<=blobLength; position += chunkSize){ int bytesRead = myBlob.getBytes(position, chunkSize, byteBuffer); out.write(byteBuffer); } //step9: close the stream obj out.close(); System.out.println("Read BLOB and save file"+saveFile); } catch(SQLException e){ System.out.println("Error Code: "+e.getErrorCode()); System.out.println("Error Message: "+e.getMessage()); e.printStackTrace(); } catch(IOException e){ System.out.println("Error Message: "+e.getMessage()); e.printStackTrace(); } } }
原文参考:http://blog.csdn.net/zhyuh_perl/article/details/7247324
发表评论
-
hibernate集合映射inverse和cascade详解
2013-05-04 12:14 908网上转载,出处不详 1、到底在哪用cascade=" ... -
java.lang.UnsupportedClassVersionError
2013-04-03 15:33 1083java.lang.UnsupportedClassVersi ... -
Hibernate实体注解
2013-04-03 15:29 1044转自:http://blog.csdn.net/sleepin ... -
转:Maven实战
2013-03-06 12:54 0转自http://www.iteye.com/topic/11 ... -
Spring定时器在SSH框架中的应用
2013-02-28 14:26 1105转自网络,来源不详.... 并非应用系统中发生的所有事情都是 ... -
ASCII字符集详解
2013-02-19 18:03 4906http://www.crifan.com/files/d ... -
安装eclipse windowbuilder
2013-02-17 10:01 2221windowbuilder,就是原来的SWT Designe ... -
点阵输出字符
2013-02-06 13:38 1189http://www.oschina.net/code/sni ... -
Hibernate主键生成策略
2013-01-28 15:50 8171) assigned 主键由外部程 ... -
结束多层循环
2013-01-23 12:28 1419没有啥意义的东西 public static void m ... -
JDBC Batch 批量插入
2013-01-22 17:02 1054JdbcBatchInsert.java import j ... -
oracle - dbms_output
2013-01-21 10:55 10681、如果dbms_output.put_line的内容不能显示 ... -
SQL not in 疑惑
2013-01-17 16:23 476在sql查询中, select * from t1 wh ... -
java.lang.UnsupportedClassVersionError: Bad version number in .class file
2013-01-17 13:30 892备忘一下: 导入一个工程后,运行时出现java.lang.Un ... -
oracle行转列的应用
2012-12-19 15:02 1041oracle 行转列应用 select t.WELLI ... -
List<Map> 自定义排序
2012-12-19 13:05 2452对list根据自定义方法排序记要 List list = ... -
后台拼接js代码字符串,处理特殊转义字符
2012-12-13 17:51 5273因为在JS程序代码中,如果生成的字符串中包含特殊字符,那程序容 ... -
Oracle 表死锁解除
2012-11-06 15:56 956我是在plsql中处理 1.先查询 select * fro ... -
plsql导出表和数据
2012-11-01 15:57 1259Tools -> Export tables -> ... -
java 实现图片裁剪
2012-10-26 15:04 14848import java.awt.Rectangle; i ...
相关推荐
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 ...
主要介绍了使用JDBC4.0操作Oracle中BLOB类型数据的方法,我们需要使用ojdbc6.jar包,本文介绍的非常详细,需要的朋友可以参考下
JDBC操纵Oracle数据库中的BLOB字段
JDBC读写Oracle的CLOB字段
JDBC+Hibernate将Blob数据写入Oracle
java jdbc如何处理Oracle___BLOB字段,以备查阅
oracle中使用jdbc读写clob字段,很多细节介绍,内容全面。
使用JDBC和Hibernate来写入Blob型数据到Oracle中;使用JDBC和Hibernate来写入Blob型数据到Oracle中
Oracle JDBC驱动包有多个版本,选错ojdbc驱动,会导致各种莫名其妙的错误,每个ojdbc版本对应的Oracel版本、JDK版本都不一样,压缩包里面有详细说明。
Struts用 JDBC Blob字段 保存和读取 Oracle 数据库 好用 试过 有详细注释
clob和blob在jdbc的应用~~~~~~
用hibernate和jdbc读存blob或clob
在Oracle数据库存储超大文件时、以流的方式分段读取和保存,避免内存溢出。本工具类提供两个方法: 1、读取文件保存到Oracle数据库Blob字段(支持超大文件) 2、从数据库中读出大字段到文件中(分块读取)
需要的jar包 使用ojdbc6.jar 在/META-INF/MANIFEST.MF里可以看到Specification-Version: 4.0 建表 ... image blob ); 将文件写入数据库 1 /** 2 * 将图片文件存入数据库 3 * @throws
很难找的weblogic支持oracle的blob的驱动包
下面以程序实例说明通过JDBC操纵Oracle数据库LOB类型字段的几种情况。 先建立如下两个测试用的数据库表,Power Designer PD模型如下: 建表SQL语句为:CREATE TABLE TEST_CLOB ( ID NUMBER(3), CLOBCOL CLOB)CREATE
rt,出现这种情况,可以更换下hibernate核心包 即可解决