Show TOC

Background documentationReading and Writing LOBs En Bloc Locate this document in the navigation structure

 

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.

Syntax Syntax

Reading LOBs en Bloc using JDBC

  1. 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();
    }
    
End of the code.
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.

Syntax Syntax

Writing LOBs en Bloc using JDBC

  1. 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();
    }
    
End of the code.