2014-05-17 2 views

답변

1

PreparedStatement의 getBlob()는 Binary 정보를 가져 오는 데 사용되며 Blob의 인스턴스를 반환합니다. blob 객체에서 getBytes() 메서드를 호출하면 이미지 파일에 쓸 수있는 이진 정보의 배열을 가져옵니다. 여기

PreparedStatement ps = con.prepareStatement("select * from MyImageTable"); 
    ResultSet rs = ps.executeQuery(); 

    if(rs.next()){ 

    Blob blob = rs.getBlob(2); //Here 2 is second column data 
    byte b[] = blob.getBytes(1,(int)b.length()); //Here 1 represent first image 

    FileOutputStream output = new FileOutputStream("e:\\some_pic.jpg"); //path goes here 
    output.write(b); 

    output.close(); 
0

체크 아웃 오라클 JDBC 개발자 가이드의 streaming lobs 섹션을 .. 코드입니다. 데이터에 액세스하는 데는 여러 가지 방법이 있습니다. 다른 옵션의 메모리/성능 영향은 서로 다릅니다. 가장 간단한 해결책은 아마도 ResultSet.getBinaryStream 일 것입니다. 그러나 데이터 길이에 대한 정보가 필요하면 getBlob을 사용할 수도 있습니다.

관련 문제