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.


/*from w  ww .ja v  a 2s.  c o 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();

  }
}




















Home »
  Java Tutorial »
    java.sql »




DatabaseMetaData
ParameterMetaData
PreparedStatement
ResultSet
Timestamp