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
|
/**
* Méthode qui remplit un preparedStatement. Apparement db2 ne supporte le
* setNull.
*/
public PreparedStatement bindPreparedStatement(PreparedStatement _stmt,
Object[] _o) throws SQLException, BatchDataException {
PreparedStatement pst = null;
try {
pst = _stmt;
// for (int i = 0; i < _o.length; i++) {
// System.out.println("i " + i + " Object " + _o[i]);
// }
for (int i = 0; i < _o.length; i++) {
//System.out.println("i " + i + " Object " + _o[i]);
if (_o[i] == null)
pst.setObject(i + 1, "");
else
pst.setObject(i + 1, _o[i]);
}
} catch (SQLException e) {
e.printStackTrace();
erreur.add("Erreur des passages des arguments au PreparedStaement "
+ e.toString());
error("Erreur des passages des arguments au PreparedStatement ", e);
}
return pst;
}
// public int[] execBatch3(Connection con, String sql, List tableauObjet )
// throws SQLException,
public int execBatchPreparedStatement(Connection con,
PreparedStatement pstmt, String nom_table, Object[] tableauObjet)
throws SQLException, BatchDataException {
// TODO Auto-generated method stub
int rest = -1;
PreparedStatement tmp = null;
try {
//System.out.println( tableauObjet );
tmp = pstmt;
tmp = bindPreparedStatement(pstmt, tableauObjet);
rest = tmp.executeUpdate();
} catch (SQLException e) {
// error("Probleme lors de l'insertion ", e);
// throw new BatchDataException("Erreur lors de l'insertion du blog
// dans la table "+ nom_table + " " + e.toString() );
erreur.add("Erreur lors de l'insertion du blog dans la table "
+ nom_table + "\n" + e.toString());
error("Probleme lors de l'insertion dans la table " + nom_table
+ "\n", e);
}
return rest; |
Partager