mardi 19 mai 2009

insérer un blob sur oracle avec JDBC

/**
* Creation d'un CLOB temporaire utilisé dans la creation et modification en base.
*
* @param clobData Valeur du CLOB
* @param pC Connection
* @return CLOB
*/
private CLOB getCLOB(String clobData, Connection pC) throws SQLException
{
CLOB tempClob = null;
try {
// create a new temporary CLOB
tempClob = CLOB.createTemporary(pC, 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(clobData);

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

// Close the temporary CLOB
tempClob.close();
}
catch (Exception exp) {
tempClob.freeTemporary();
throw new SQLException(exp.getMessage());
}
return tempClob;
}

plus d'info sur
: http://www.herongyang.com/jdbc/Oracle-CLOB-getCharacterStream.html

Aucun commentaire:

Enregistrer un commentaire