JDBC: retrieve values from BLOB or CLOB
October 18, 2008 02:46:56 Last update: October 18, 2008 02:47:33
There are four pairs of methods in the
Example code:
java.sql.ResultSet class that deal with BLOBs/CLOBs:
-
Reader getCharacterStream(int columnIndex)/Reader getCharacterStream(String columnName) -
InputStream getBinaryStream(int columnIndex)/InputStream getBinaryStream(String columnName) -
Blob getBlob(int i)/Blob getBlob(String colName) -
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();
Easy email testing with http://www.ximailstop.com