| Usuario |
convertir String a CLOB |
Desconocido
|
| Enviado - 18/10/2004 |
| |
Hola chicos!
Una vez más tengo problemas con una cosilla de Java.. haber si alguno de vosotros le ha tocado pegarse con esto y me podeis echar una manaza!!
Vamos a ver... el problema es el siguiente:
Tengo que llamar a una funcion en ORACLE que recibe un parametro de entrada de tipo CLOB. La forma de pasar este parametro es mediante el metodo setClob de la clase CallableStatement.
import oracle.sql.CLOB;
String clob_str;
CallableStatement cstmt=null;
clob_str = "Hola gente"
int cont = 0;
cstmt.setClob(cont,¿¿clob_str??);
El problema está en la forma de pasar el segundo parámetro a esta llamada, pq requiere un tipo CLOB y tengo un String. No puedo utilizar cstmt.setString(cont,clob_str) pq la funcion de ORACLE requiere nun tipo oracle.sql.CLOB. He buscado en internet y he encontrado una funcion que me hace esa conversion.. pero me salta una exception en la primera de las sentencias.
¿Alguno ha trabajado con lo algo parecido a esto??:
------------------------- METODO QUE CONVIERTE UN STRING A CLOB
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();
} catch(Exception exp){
tempClob.freeTemporary();
exp.printStackTrace();
}
return tempClob;
}
------------------------------------------------------
--- ASí esta declarado el metodo de la clase CLOB:
public static CLOB createTemporary(java.sql.Connection conn,
boolean cache,
int duration)
throws java.sql.SQLExceptionCreate a temporary clob.
Parameters:
cache - Specifies if LOB should be read into buffer cache or not.
duration - The duration of the temporary LOB. The following are valid values: DURATION_SESSION, DURATION_CALL.
Returns:
A temporary clob.
Since:
8.2.0
------------------------------------------------------
Gracias y un saludo. Gema |
| |
|
|
|