中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 数据库开发 > 数据库综合
Oracle 操作图片
作者:未知 时间:2002-07-18 12:12 出处:Blog 责编:chinaitpower
              摘要:暂无

Oracle 操作图片

 

Blobtest.java
Created with JBuilder

package testapp;

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

public class Blobtest {

    public Blobtest() {
    }

  public static void main (String args [])
       throws SQLException, IOException
  {
    //write();
    read();

  }

  static  void read() throws SQLException, IOException  {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn =
      DriverManager.getConnection ("jdbc:oracle:thin:@ebizser:1521:serverdb", "scott", "tiger");

    // It's faster when you don't commit automatically
    conn.setAutoCommit (false);

    // Create a Statement
    Statement stmt = conn.createStatement ();


    // Do a query to get the row with NAME 'StreamExample'
    ResultSet rset =
      stmt.executeQuery ("select col2 from lobtest where userid=1");

    // Get the first row
    if (rset.next ())
    {
      // Get the data as a Stream from Oracle to the client
      InputStream gif_data = rset.getBinaryStream (1);

      // Open a file to store the gif data
      FileOutputStream os = new FileOutputStream ("example.jpe");

      // Loop, reading from the gif stream and writing to the file
      int c;
      while ((c = gif_data.read ()) != -1)
        os.write (c);

      // Close the file
      os.close ();
    }

    // Close all the resources
    if (rset != null)
      rset.close();

    if (stmt != null)
      stmt.close();

    if (conn != null)
      conn.close();
  }

  static void write()  throws SQLException, IOException {

     DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn =
      //DriverManager.getConnection ("jdbc:oracle:thin:@ebizser:1521:serverdb", "scott", "tiger");
      DriverManager.getConnection ("jdbc:oracle:oci8:@ebdb", "scott", "tiger");

    // It's faster when you don't commit automatically
    conn.setAutoCommit (false);

    // Create a Statement


    File file = new File("C:\\Documents and Settings\\gzb.ECOM\\My Documents\\My Pictures\\28-3-16933_jinxishan34s.jpe");

    InputStream is = new FileInputStream ("C:\\Documents and Settings\\gzb.ECOM\\My Documents\\My Pictures\\28-3-16933_jinxishan34s.jpe");
    PreparedStatement pstmt =
      conn.prepareStatement ("insert into lobtest (userid, col2 ) values (?, ?)");

    pstmt.setBinaryStream(2, is, (int)file.length ());
    pstmt.setInt (1, 2);
    pstmt.execute ();


    if (pstmt != null)
      pstmt.close();

    if (conn != null)
      conn.close();
  }

}

Blobtest.java
Created with JBuilder

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有