Show TOC

Reading and Writing LOBs En BlocLocate this document in the navigation structure

Use

Reading and writing LOBs en bloc implies that either you retrieve the value of the BLOB and CLOB columns into a byte array or a string, or you insert data from a byte array or a string.

Activities

Reading LOBs en Bloc

The JDBC API provides the methods getBytes() and getString() methods of java.sql.ResultSet . They enable you to read BLOB or CLOB columns into a byte array or a string respectively.

Reading LOBs en Bloc using JDBC

               String query = "select REFMANUAL, PICTURE from BC_CR_VEHICLE " +
        "where NAME = ?";
PreparedStatement ps = conn.prepareStatement(query);
try {
  ps.setString(1, "Golf");
  ResultSet rs = ps.executeQuery();
  try {
        while (rs.next()) {
                String refManual = rs.getString("REFMANUAL");
                byte[] image = rs.getBytes("PICTURE");
  ...
        }
  finally {
        rs.close();
  }
finally {
  ps.close();
}

            

Writing LOBs en Bloc

To insert data from a byte array or a string with JDBC , you should use setBytes() or setString() methods of java.sql.PreparedStatement .

Writing LOBs en Bloc using JDBC

               String manual = "...";
byte[] picture = ...;

String insertStmt = "insert into VEHICLE " +
        "(NAME, REFMANUAL, PICTURE) VALUES (?, ?, ?)";
PreparedStatement ps = conn.prepareStatement(insertStmt);
try {
        ps.setString(1, "Golf");
        ps.setString(2, manual);
        ps.setBytes(3, picture);
        ps.executeUpdate()
}finally{
ps.close();
}