• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Oracle 操作图片

发布: 2007-7-02 11:08 | 作者: admin | 来源: | 查看: 8次 | 进入软件测试论坛讨论

领测软件测试网
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

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网