Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.io.*;
- public class RetrieveImageFile {
- public static void main(String[] args) {
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection con=DriverManager.getConnection(
- "jdbc:oracle:thin:@localhost:1521:DB","USER","PSWD");
- PreparedStatement ps=con.prepareStatement("select * from table");
- ResultSet rs=ps.executeQuery();
- if(rs.next()){//now on 1st row
- Blob b=rs.getBlob(1); // IMAGE COLUMN NO
- byte byteArray[]=b.getBytes(1,(int)b.length());
- FileOutputStream fout=new FileOutputStream("d:\image.jpg");
- fout.write(byteArray);
- fout.close();
- }
- System.out.println("Image loaded successfully");
- con.close();
- }catch (Exception e) {e.printStackTrace(); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement