• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Oracle 操作图片_oracle

oracle 搞代码 7年前 (2018-06-14) 259次浏览 已收录 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

欢迎大家阅读《Oracle 操作图片_oracle》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Oracle 操作图片_oracle
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址