Java API Tutorial - Java ResultSet.getBinaryStream(int columnIndex)








Syntax

ResultSet.getBinaryStream(int columnIndex) has the following syntax.

InputStream getBinaryStream(int columnIndex)    throws SQLException

Example

In the following code shows how to use ResultSet.getBinaryStream(int columnIndex) method.

/*  w w w.j  a va  2  s.  co m*/

import java.awt.Image;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.sql.ResultSet;

public class Main {
  public static void main(String[] argv) throws Exception {
    ResultSet rset = null;
    InputStream stream = rset.getBinaryStream(1);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    int a1 = stream.read();
    while (a1 >= 0) {
      output.write((char) a1);
      a1 = stream.read();
    }
    Image myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray());
    output.close();

  }
}