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
pst.setString(1,lcode);

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

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

if( result.next() ) {

// 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
FileOutputStream(gifFile);

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

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.: