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
|
public void selectLine(Long number) {
Connection cx = null;
PreparedStatement ps = null;
try {
String query = "SELECT type_number, type_char, type_varchar, type_date, type_clob, type_blob, type_raw "
+ " FROM JDBC_DRIVER_BENCHMARK WHERE type_number = ?";
cx = openConnection();
ps = cx.prepareStatement(query);
ps.setLong(1, number);
ps.executeQuery().getFetchSize();
}
catch (SQLException sqle) {
throw new QueryException(sqle);
}
catch (NamingException e) {
logger.log("No JDBC connection available from connection pool", Logger.ERROR);
throw new QueryException(e);
}
finally {
closeConnection(ps, cx);
}
}
/**
* Ouverture d'une connexion JDBC.
*/
private Connection openConnection()
throws NamingException, SQLException {
DataSource ds = null;
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:/OracleDS");
return ds.getConnection();
}
/**
* Fermeture d'une connexion JDBC.
*/
private void closeConnection(PreparedStatement ps, Connection cx) {
if (ps != null) {
try {
ps.close();
}
catch (Exception e) {logger.log(Utility.exceptionToString(e), Logger.ERROR);}
}
if (cx != null) {
try {
cx.close();
}
catch (Exception e) {logger.log(Utility.exceptionToString(e), Logger.ERROR);}
}
} |
Partager