首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > Oracle 操作图片
【标  题】:Oracle 操作图片
【关键字】:c,操作,图片,Oracle,Oracle
【来  源】:网络

Oracle 操作图片

Oracle 操作图片

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();
}

}

从数据库读出的JPG文件的字符流,转换成图片显示在页面上的相关代码:【上一篇】
Oracle 数据库 系统使用经验六则:【下一篇】
【相关文章】
  • 从数据库读出的JPG文件的字符流,转换成图片显示在页面上的相关代码
  • 从数据库中读出图片并显示的示例代码
  • jdbc应用--数据库连接全集
  • 一个简单的JDBC包装器(1)
  • Java数据库接口JDBC基础教程之驱动设置
  • 学习MySQL常用操作命令
  • 对一个简单的JDBC包装器的扩展及应用(1)
  • J2EE应用中与Oracle数据库的连接
  • 对一个简单的JDBC包装器的扩展及应用(2)
  • 基于JDBC的数据库连接池高效管理策略
  • 【随机文章】
  • 实例学用CorelDRAW9(二)
  • cpumask_of_cpu()
  • 電腦愛好者出過一本,很不錯我就是看那本
  • Game Programming with DirectX -- 02[并非3D的3D]
  • Advanced Zip Password Recovery 3.0的脱壳
  • CoolStreaming/DONet: 一个用于实时流媒体传输的数据驱动型重叠网络 ( 第三节 )
  • VB COM基础讲座之ActiveX EXEs
  • Dns 服务器安装日志
  • PHP中AJAX比较(转)
  • redhat as 4 制作各种RAID和LVM的使用
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.