JDBC: retrieve values from BLOB or CLOB 

Joined:
04/09/2007
Posts:
710

October 18, 2008 02:46:56    Last update: October 18, 2008 02:47:33
There are four pairs of methods in the java.sql.ResultSet class that deal with BLOBs/CLOBs:
  1. Reader getCharacterStream(int columnIndex)/Reader getCharacterStream(String columnName)
  2. InputStream getBinaryStream(int columnIndex)/InputStream getBinaryStream(String columnName)
  3. Blob getBlob(int i)/Blob getBlob(String colName)
  4. Clob getClob(int i)/Clob getClob(String colName)


Example code:
PreparedStatement pstmt = conn.prepareStatement("SELECT image FROM photos where id = ?");
pstmt.setInt(100);
ResultSet rs= pstmt.executeQuery();
while(rs.next()) {
    InputStream in = rs.getBinaryStream(1);
    ...
} 
rs.close();
Share |
| Comment  | Tags
 
Easy email testing with http://www.ximailstop.com