| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Writing Clobs with the thin driver
Hi,
you can do this first updating the clob field with the Oracle function
EMPTY_CLOB()
and then re-query the row. When you read the content of clob field with
resultset.getClob("FILED_CLOB_NAME") you obtain a pointer to a oracle clob
area
and the you can write it.
I give you the code fragment (ASSUME THAT YOU HAVE A TABLE CALLED CLOBTEST
WITH
TWO FIELD FRST (NUMBER), SEC CLOB)
PreparedStatement ps = con.prepareStatement("UPDATE CLOBTEST =
EMPTY_CLOB() WHERE FRST =1");
ps.executeUpdate();
ps.close();
ps = null;
// Recupero della riga inserita per aggiornamento del BLOB Statement stmt = con.createStatement(); ResultSet curr_RecordSet = stmt.executeQuery("SELECT sec FROM clobtest WHERE frst = 1 FOR UPDATE");
if( curr_RecordSet.next() ) {
// Creazione BLOB vuoto ottenuto da EMPTY_BLOB()
Clob a_blb = curr_RecordSet.getClob(1);
// Puntatore all'area di memoria Oracle di salvataggio del BLOB
OutputStream clobOutputStream =
((oracle.sql.CLOB)a_blb).getAsciiOutputStream();
// Scrittura del BLOB nell'area di memoria Oracle
clobOutputStream.write("PUT YOUR TEXT HERE!".getBytes());
clobOutputStream.close();
}else{
throw new SQLException("Errore recupero record TEST");
}
Best Regards
D.
"Cookie Monster" <cookie.monster_at_somewhere.com> ha scritto nel messaggio
news:2vh3g4F2kmf5sU1_at_uni-berlin.de...
> Hi,
>
> I have a problem with the oracle thin driver writing clobs greater then
4000
> chars. Basically using the oci driver the following java code works fine:
>
> PreparedStatement statement;
> Reader bodyReader = null;
> try {
> bodyReader = new StringReader(parameter.toString());
>
statement.setCharacterStream(1,bodyReader,parameter.toString().length());
> } catch (Exception e) {
> e.printStackTrace();
> throw new SQLException("Failed to set text field.");
> }
>
> But when using with the thin driver nothing gettings written to the clob.
> Does anyone know a solution to this problem where I can use the thin
driver
> for writing clobs??
>
> Thanks,
> Steve.
>
>
Received on Thu Nov 11 2004 - 08:45:51 CST
![]() |
![]() |