1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
try {
// auto commit à false pour pouvoir envoyer le flux dans le BLOB Oracle
conn.setAutoCommit(false);
// On effectue un select for update nécessaire à l'envoi de fichier long dans la base de donnée
// l'exécution simple de setBlob , ne permet pas l'envoi au dessus de 4Ko ( ou alors c'est à approfondir)
pstmt = conn.prepareStatement(property.getProperty("Utilisateur.PreqSQL.updatePersoParamBean.selectForUpdate"));
pstmt.setInt(1, user.getId().intValue());
pstmt.setInt(2, Constantes.getConstante("CST_TYPE_PERSO.PERSO_PARAM_BEAN"));
rs = pstmt.executeQuery();
if(rs.next()) {
try {
// On récupère le BLOB Oracle puis l'OutputStream
// afin d'écrire le document dedans.
BLOB b = ((OracleResultSet)rs).getBLOB("paramBlob");
if(b != null) {
OutputStream outBlob = b.getBinaryOutputStream();
if(outBlob != null) {
int bufferSize = b.getBufferSize();
int length = 0;
byte[] btab = new byte[bufferSize];
while((length = in.read(btab)) != -1) {
outBlob.write(btab, 0, length);
}
outBlob.close();
in.close();
} else {
init.log("updatePersoParamBean(" + user.getIdWeb() + ") : outBlob==null", LogWriter.DEBUG);
}
} else {
init.log("updatePersoParamBean(" + user.getIdWeb() + ") : b==null", LogWriter.DEBUG);
}
} catch(Exception exBlob) {
init.log(exBlob, "updatePersoParamBean(" + user.getIdWeb() + "):exBlob:1", LogWriter.ERROR);
}
} else {
init.log("updatePersoParamBean(" + user.getIdWeb() + ") : rs.next==false", LogWriter.DEBUG);
}
rs.close();
pstmt.close();
conn.commit();
} catch(Exception exBlob2) {
exBlob2.printStackTrace();
init.log(exBlob2, "updatePersoParamBean(" + user.getIdWeb() + "):exBlob:2", LogWriter.ERROR);
} finally {
try {
rs.close();
} catch(Exception dummy) {
dummy.printStackTrace();
}
try {
pstmt.close();
} catch(Exception dummy) {
dummy.printStackTrace();
}
try {
conn.rollback();
} catch(Exception dummy) {
dummy.printStackTrace();
}
try {
conn.setAutoCommit(true);
} catch(Exception dummy) {
dummy.printStackTrace();
}
} |
Partager