oracle 处理图片,Oracle 操作图片

Oracle 操作图片

作者:网络 来源:佚名 更新时间:2008-02-09 10:44:37

点击:0

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.javacreated with jbuilder

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值