/**
*
* @author Jasmine
*/
public class GetBlob
{
public static void main(String[] args)
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
Class.forName(driver);
System.out.println("class");
conn = DriverManager.getConnection(url, "lyy", "lyy");
System.out.println("connect");
stmt = conn.createStatement();
String sql = "select files from lyy.filetable where id=4";
rs = stmt.executeQuery(sql);
System.out.println("sql="+sql);
while (rs.next())
{
      System.out.println(rs.getMetaData().getColumnTypeName(1));

//获取locator
BFILE bf = (BFILE)rs.getObject(1);
System.out.println("isFileOpen="+bf.isFileOpen());
OutputStream ops = null;
InputStream ips = null;
File file = new File("e:"+File.separator+bf.getName());
try
{
    System.out.println(""+bf.fileExists());
    bf.openFile();
    ips = bf.getBinaryStream();
    byte[] buffer =new byte[bf.getBytes().length];
    ops = new FileOutputStream(file);

//生成os系统文件

for (int i; (i = ips.read(buffer)) > 0;)
   {
        System.out.println("i=" + i);
        ops.write(buffer, 0, i);
        ops.flush();
    }

catch (Exception ex)
{
       ex.printStackTrace(System.out);
}
finally
{
      ips.close();
      bf.closeFile();
      ops.close();
}

}

}
catch (Exception ex)
{
       ex.printStackTrace(System.out);
}
finally
{
     try
    {
           rs.close();
           stmt.close();
           conn.close();
    }
    catch (SQLException ex)
    {
           Logger.getLogger(GetBlob.class.getName()).log(Level.SEVERE, null, ex);
     }
}
}
}

java读取Oracle的BFile文件的更多相关文章

  1. Java读取oracle数据库中blob字段数据文件保存到本地文件(转载)

    转自:https://www.cnblogs.com/forever2698/p/4747349.html package com.bo.test; import java.io.FileOutput ...

  2. Java读取Level-1行情dbf文件极致优化(3)

    最近架构一个项目,实现行情的接入和分发,需要达到极致的低时延特性,这对于证券系统是非常重要的.接入的行情源是可以配置,既可以是Level-1,也可以是Level-2或其他第三方的源.虽然Level-1 ...

  3. Java读取Level-1行情dbf文件极致优化(2)

    最近架构一个项目,实现行情的接入和分发,需要达到极致的低时延特性,这对于证券系统是非常重要的.接入的行情源是可以配置,既可以是Level-1,也可以是Level-2或其他第三方的源.虽然Level-1 ...

  4. java读取各类型的文件

    java读取各类型的文件 用到的几个包 bcmail-jdk14-132.jar/bcprov-jdk14-132.jar/checkstyle-all-4.2.jar/FontBox-0.1.0-d ...

  5. Java读取并下载网络文件

      CreateTime--2017年8月21日10:11:07 Author:Marydon import java.io.ByteArrayOutputStream; import java.io ...

  6. java读取数据写入txt文件并将读取txt文件写入另外一个表

    package com.xsw.test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.F ...

  7. java读取UTF-8的txt文件发现开头的一个字符问题

    今天遇到一个奇葩问题,在读取一个TXT文件时,出现开头多了一个问号(?).如下图: 莫名奇妙的多了一个.最后通过网上资料,知道在Java中,class文件采用utf8的编码方式,JVM运行时采用utf ...

  8. Java读取CSV和XML文件方法

    游戏开发中,读取策划给的配置表是必不可少的,我在之前公司,策划给的是xml表来读取,现在公司策划给的是CSV表来读取,其实大同小异,也并不是什么难点,我就简单分享下Java如何读取XML文件和CSV文 ...

  9. Java 读取jar内的文件的超简便方法

    坑爹的java课程设计,偏要用jar来运行 读取.存储jar内文件的支持也好低 存储方法: 进入jar文件其实没有说的那么困难,jar文件本质是一个zip格式的压缩文件,只是把文件后缀名改了,要用Ja ...

随机推荐

  1. RedHat6/Centos6.5安装mongodb php driver

    条件: 安装apache 安装php 1.下载mongodb phh driver 下载地址:pecl wget http://pecl.php.net/get/mongo-1.5.8.tgz 2.解 ...

  2. RedHat6/Centos6.5安装mongodb

    1 设置mongodb目录 [root@localhost /]# cd home/ [root@localhost home]# mkdir mongodb/db 2 配置yum [root@loc ...

  3. DumpBinary

    stdafx.h #include "targetver.h" #include <stdio.h> #include <tchar.h> #include ...

  4. IO多路复用、协程

    一.铺垫:基于socket发送http请求 1.需求一:向百度发送请求搜索关键字“alex”,有如下两种方式: import requests ret = requests.get('https:// ...

  5. 【生产问题】-dbcc checkdb报错-数据页故障

    更多操作参考:https://www.cnblogs.com/gered/p/9435282.html [生产问题]-dbcc checkdb报错-数据页故障 数据页故障,索引页故障 use db_t ...

  6. Ubuntu出现Authentication failure(认证失败)的解决方法(转)

    当我们想在刚安装的Linux系统启动某些服务或者想进入root用户时提示认证失败或者权限不够时,原因是刚安装Ubuntu后,root用户默认是未激活的,不允许登录,也不允许使用su命令到转到root用 ...

  7. python——单例模式

    单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在. 当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. 比如, ...

  8. nfs共享存储

    1.下载软件包 yum install nfs-utils nfs-utils-lib -y 2.编辑/etc/exports文件: 1.创建目录:mkdir -p /home/glance2.编辑e ...

  9. 安装MySQL的详细步骤

    安装步骤如下: 1.打开网址:http://www.mysql.com/ ↓ 2.选择“Download”->“Windows”(此安装步骤只是在Window10 中进行,如有需要,其他系统可参 ...

  10. UI控件之UINavigationController

    ViewController1 *vc1=[[ViewController1 alloc]init]; UINavigationController *nav1=[[UINavigationContr ...