Java - Ayuda - Convertir String a Clob

 
Vista:

Ayuda - Convertir String a Clob

Publicado por nini (2 intervenciones) el 25/09/2006 10:54:24
Hola,

necesito convertir un dato de tipo String a Clob, para insertarlo en la BBDD.
¿sabríais como hacerlo?

Gracias y un saludo, Nieves
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Ayuda - Convertir String a Clob

Publicado por Pablo (1 intervención) el 06/10/2006 17:31:25
Uno de los metodos mas utilizados y mas comunque podrás encontrar es este.
Saludos
Pablo

private CLOB getCLOB(String xmlData, Connection conn) throws SQLException{
CLOB tempClob = null;
try{
// If the temporary CLOB has not yet been created, create new
tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);

// Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);
// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();
// Write the data into the temporary CLOB
tempClobWriter.write(xmlData);

// Flush and close the stream
tempClobWriter.flush();
tempClobWriter.close();

// Close the temporary CLOB
tempClob.close();
} catch(SQLException sqlexp){
tempClob.freeTemporary();
sqlexp.printStackTrace();
if(conn!=null )conn.close();
} catch(Exception exp){
tempClob.freeTemporary();
exp.printStackTrace();
if(conn!=null )conn.close();
}
return tempClob;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar