import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ReaderIO {
private Connection con = null;
private Statement st = null;
private InputStream in = null;
private OutputStream out = null;
private BufferedInputStream bis = null;
private ResultSet rs = null;
public ReaderIO(){
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@***.**.**.**:1522:***","**","**");
st = con.createStatement();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void getFile(String condition){
String sql ="select * from report.info_report r where r.report_name like '" + condition + "'";
try{
rs = st.executeQuery(sql);
while(rs.next()){
in = rs.getBlob(9).getBinaryStream();
bis = new BufferedInputStream(in);
out = new FileOutputStream(new File("e://" + rs.getString(2) + ".raq"));
byte[] bit = new byte[1024];
while((bis.read(bit)) > 0){
out.write(bit, 0, bit.length);
}
reset();
}
}catch(SQLException e){
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
close();
}
}
public void close(){
try{
if(rs != null){
rs.close();
}
if(st != null){
st.close();
}
if(con != null){
con.close();
}
}catch(SQLException e){
}
}
public void reset(){
try{
if(in != null){
in.close();
}
if(bis != null){
bis.close();
}
if(out != null){
out.close();
}
}catch(IOException e){
}
}
public static void main(String[] rags){
ReaderIO ri = new ReaderIO();
ri.getFile("测试%");
}
}