jueves, octubre 04, 2007

Programmatically Build a Spring Application Context

¿Cómo contruir un contexto de Spring programaticamente?
Respuesta en el Link.

viernes, septiembre 28, 2007

Dates in HSQLDB

Encontre un link para el manejo de fechas en HSQL (y muestra el ejemplo con Oracle).
Para obtener
2007-09-28

Se hace:

year(current_date) '-' month(current_date) '-'
(dayOfMonth(current_date)-60

El post original está aquí.

jueves, febrero 08, 2007

Flavors to Printer

DocFlavor[] flavors = impSelected.getSupportedDocFlavors();
for (int i = 0; i < flavors.length; i++ ) {
try {
System.out.println(BeanUtils.describe(flavors[1]).toString());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
} // for

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.