martes, enero 02, 2007

LongRaw Datatype Oracle

      String query = "SELECT name,airline_logo FROM " +
"otn_airline_longraw WHERE code=?"

// Create a PreparedStatement object for executing the query
PreparedStatement pst = connection.prepareStatement(query);

// bind the parameter with code value

// Obtain the result-set for the selected airline record
ResultSet result = pst.executeQuery();

// get user home folder name
userHome = System.getProperty("user.home");

if( ) {

// Fetch column values
name = result.getString(1); // Obtain the airline code

// append the file name with user home directory, file separator and
// file extension GIF
fullName = userHome+File.separator+name+".gif";

// LONGRAW data can be accessed in two ways:
// 1) By retrieving all the data at once (using getBytes method)
// 2) By using streams. The LONGRAW data is made available to the program
// as a stream, and the data can be retrieved chunk by chunk, which is
// more eficient in terms of memory usage
// In this sample we illustrate retrieval using streams method.
gifdata = result.getBinaryStream(2);
// create new file
File gifFile = new File(fullName);

// Write the byte array into a local file
FileOutputStream file= new

int chunk=0;
// write to the local file until image (LONGRAW) data is found
while( (chunk = != -1) {

El ejemplo competo está acá [Cátalogo de ejemplos].
Creo que tiene las mejores practicas las clases:
Hace falta un finally para cerrar recursos.
Declarar como final algunos objetos.

No hay comentarios.: