Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.sql.*;
  2. import java.io.*;
  3. public class RetrieveImageFile {
  4. public static void main(String[] args) {
  5. try{
  6. Class.forName("oracle.jdbc.driver.OracleDriver");
  7. Connection con=DriverManager.getConnection(
  8. "jdbc:oracle:thin:@localhost:1521:DB","USER","PSWD");
  9.  
  10. PreparedStatement ps=con.prepareStatement("select * from table");
  11. ResultSet rs=ps.executeQuery();
  12. if(rs.next()){//now on 1st row
  13.  
  14. Blob b=rs.getBlob(1); // IMAGE COLUMN NO
  15. byte byteArray[]=b.getBytes(1,(int)b.length());
  16.  
  17. FileOutputStream fout=new FileOutputStream("d:\image.jpg");
  18. fout.write(byteArray);
  19.  
  20. fout.close();
  21. }
  22. System.out.println("Image loaded successfully");
  23.  
  24. con.close();
  25. }catch (Exception e) {e.printStackTrace(); }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement