读取oracle blob字段

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class getFlow {

    /** * @param <CLOB> * @param args * @throws IOException * @throws SQLException */
    public static  void main(String[] args) throws IOException, SQLException {
        DatabaseConnection dbc = new DatabaseConnection();
        Connection conn = dbc.getConnection();
        Blob blob = null;
        String sql = "select * from OA2_FORM where fr_ident='72047'";
        try {
            PreparedStatement stmt = conn.prepareStatement(sql);
            ResultSet rs = stmt.executeQuery();
            if (rs.next()) { 
                blob = rs.getBlob("FR_DATA"); 
                //printBlob(blob);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            conn.close();
        }
        String content = new String(blob.getBytes((long)1, (int)blob.length()),"utf-8");
        System.out.println(content);
    }
}

你可能感兴趣的:(读取oracle blob字段)