⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readerblobdata.java

📁 关于向orcle数据库内插入与读取Blob型数据
💻 JAVA
字号:
package com;

import java.io.*;
import java.sql.*;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2009-2-26
 * Time: 15:30:02
 * To change this template use File | Settings | File Templates.
 */
public class ReaderBlobData {
    public static void main(String args[]) {

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.148:1521:orcl102g", "xux", "xux");
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select   *   from   teacher where tid=1");
            InputStream is = null;
            while (rs.next()) {
                is = rs.getBinaryStream(5);
            }
            FileOutputStream fos = new FileOutputStream("D:\\3.jpg");
            byte[] b = new byte[6200];
            is.read(b);
            fos.write(b);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }


    }


//    想数据库中插入blob类型的数据如图片
  /*  public   static   void   main(String   args[])   throws   Exception
  {
  File   f   =   new   File("b.jpg");
  long   length   =   f.length();

  FileInputStream   fis   =   new   FileInputStream("b.jpg");
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection   conn   =   DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora9i","scott","tiger");

  PreparedStatement   pstmt   =   conn.prepareStatement("insert   into   image   values(?,?,?)");

  pstmt.setString(1,"b.jpg");
  pstmt.setInt(2,(int)length);
  pstmt.setBinaryStream(3,fis,(int)length);
  pstmt.executeUpdate();
  pstmt.close();
  conn.close();


  } */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -