0

I'm using JDBC to connect to the oracle database. I know how to retrieve various data (strings, ints, etc.), but I don't know how to get ORDImage from this database. Is there any ResultSet method to accomplish this?

1
  • The getBlob() method of PreparedStatement. Commented May 17, 2014 at 18:13

3 Answers 3

1

getBlob() of PreparedStatement is used to get Binary information, it returns the instance of Blob. By calling the getBytes() method on the blob object, you will get the array of binary information that can be written into the image file.

Here is the code..

   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();  
Sign up to request clarification or add additional context in comments.

Comments

0

Check out the streaming lobs section of the oracle jdbc developers guide. There are several ways to access the data. There are different memory/performance impacts of the different options. The simplest solution is probably ResultSet.getBinaryStream. But if you want information about length of data, you can also use getBlob.

Comments

0

There are lot of ways to display to retrieve image from database in java library, this one is of the best way to retrieve image from database to java swing form and can display in JLable according to your required size.

        ResultSet rs = stmnt.executeQuery("select * from table1 ");
        Blob blob= rs.getBlob("image");
        byte bt[]= blob.getBytes(1,(int)blob.length());
        Image img= ImageIO.read(new ByteArrayInputStream(bt));
        Image img1= img.getScaledInstance(200,230,Image.SCALE_SMOOTH);
        ImageIcon icon= new ImageIcon(img1);

        JLable1.setIcon(icon);

Example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.