读出blob字段

news/2024/5/19 0:21:21 标签: string, import, null, exception, jdbc, sql

import java.io.*;
import java.sql.*;

import oracle.jdbc.*;
import oracle.sql.*;

/**
 * <p>名称: BLOBRead.java </p>
 * <p>说明:
 * 业务规则:
 * 读出blob字段
 * </p>
 * <p>版权: Copyright (c) 2006</p>
 * <p>版权所有: 北大青鸟软件工程有限公司</p>
 * @author 王世元
 * @version 1.0
 */

public class BLOBRead {
  public static void main(String[] args) {
    Connection con = null;
    try {
      //连接字串
      Class.forName("oracle.jdbc.driver.OracleDriver");

      //数据库地址
      String url = "jdbc:oracle:thin:@192.168.100.100:1521:wangsy";

      //创建连接
      con = DriverManager.getConnection(url, "wangsy", "wangsy");

      //取消自动提交
      con.setAutoCommit(false);

      Statement stmt = con.createStatement();

      //使用"for update"得到表的写锁
      String sql = "select strustring from treestructure where structureid=" +
          1;
      ResultSet rs = stmt.executeQuery(sql);

      BLOB blob = null;

      //写出为文件
      //File out=new File("c:/outtest1.txt");
      //java.io.FileOutputStream fout=new FileOutputStream(out);

      //输出字符串
      String structureXML = "";

      byte[] b = null;
      while (rs.next()) {
        String tmpStr = "";
        blob = (oracle.sql.BLOB) rs.getBlob("strustring");
        b = blob.getBytes(1, (int) blob.getLength());

        //输入流
        InputStream in = blob.getBinaryStream();
        DataInputStream dd = new DataInputStream(in);
        while ( (tmpStr = dd.readLine()) != null) {
          System.out.println("tmpStr " + tmpStr);
          structureXML = structureXML + tmpStr;
        }
        in.close();
        dd.close();

      }

      //关闭连接
      con.close();
    }
    catch (Exception ex) {
      try {
        con.rollback();
      }
      catch (SQLException ex1) {
        System.out.println(ex1.getMessage());
      }
    }
  }
}


http://www.niftyadmin.cn/n/1405993.html

相关文章

三种C#.net生成静态页面的方法

ASP.NET生成静态页面方法主要有三种第一种方法&#xff1a;向服务器的动态页面发送请求&#xff0c;获取页面的html代码。这种方法缺点显而易见&#xff1a;速度慢。另外如果请求的动态页面有验证控件的话&#xff0c;返回的html页面却无法进行数据验证。但这种方法写起来比较简…

html5 video 直播流无声音,H5使用Video标签上传视频有声音无画面的解决方案

前端用H5的Video标签做了播放器&#xff0c;部分mp4文件上传成功后只有声音而没有画面&#xff0c;经过了解之后才知道此标签只支持编码为H264的MP4文件&#xff0c;不支持编码为MPEG4的MP4文件&#xff0c;想成功播放必须要转码。于是就去网上找啊找&#xff0c;刚开始全是格式…

写入blob字段

import java.io.*;import java.sql.*; import oracle.jdbc.*;import oracle.sql.*; /** * <p>名称&#xff1a; BLOBWrite.java </p> * <p>说明&#xff1a; * 业务规则&#xff1a; * 写入blob字段 * </p> * <p>版权&#xff1a; Copyright (…

IIS7.0 webconfig的urlrewrite

地址重写有助于搜索引擎收录。<<add roles>>

更新blob的方法示例

/** * 更新配置结构 * param structureID String 结构标志符 * throws Exception */ public void update(String structureID,String xml,HXConn con) throws Exception { //先删除树型信息表和触发时间表中的记录 this.delete(structureID,con); //再更新树…

html获取中国天气,中国天气网城市代码(JSON)获取实现(一)

这篇文章中贴出china的所有城市及其具体的管辖范围及所属情况&#xff0c;可复制保存为city.json文件。下面将来对城市代码的JSON文件进行获取与查询&#xff1a;获取主类&#xff1a;CityCode.javapackage com.eabour.weather;import java.util.ArrayList;import java.util.Ha…

解决与处理网站高并发 大流量访问的方法

首先&#xff0c;确认服务器硬件是否足够支持当前的流量 普通的P4服务器一般最多能支持每天10万独立IP&#xff0c;如果访问量比这个还要大&#xff0c; 那么必须首先配置一台更高性能的专用服务器才能解决问题 &#xff0c;否则怎么优化都不可能彻底解决性能问题。 其次&#…

HTML之frameset标记

frameset框架的标记&#xff0c;主要是分割窗口和插入浮动窗口的功能。需要配合frame标记。frameset标记是个双标记 重要属性&#xff1a;rows框架所占用的行数(rows"10,*"表示占10行&#xff0c;rows"*"表示占窗口全部行)cols框架所占用的列数(cols"…