数据库

本类阅读TOP10

·SQL语句导入导出大全
·SQL Server日期计算
·SQL语句导入导出大全
·SQL to Excel 的应用
·Oracle中password file的作用及说明
·MS SQLServer OLEDB分布式事务无法启动的一般解决方案
·sqlserver2000数据库置疑的解决方法
·一个比较实用的大数据量分页存储过程
·如何在正运行 SQL Server 7.0 的服务器之间传输登录和密码
·SQL中两台服务器间使用连接服务器

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Oracle 操作图片

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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




相关文章

相关软件