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
|
public type_retour fonction(objetc o) {
Connection conn = null;
Statement stmt=null;
ResultSet rst=null;
try{
conn = //recupération d'une connexion depuis un pool tomcat if(conn != null) {
stmt = conn.createStatement();
rst = stmt.executeQuery("une requette");
while(rst.next()) {
/*
code de traitement
*/
int toto=ma_fonction2()
}
rst.close();
rst = null;
stmt.close();
stmt = null;
conn.close(); // Return to connection pool
conn = null; // Make sure we don't close it twice
}
}catch (SQLException e) {
e.printStackTrace();
//... deal with errors ...
}catch (Exception e2) {
e2.printStackTrace();
//... deal with errors ...
} finally {
// Always make sure result sets and statements are closed,
// and the connection is returned to the pool
if (rst != null) {
try { rst.close(); } catch (SQLException e) { ; }
rst = null;
}
if (stmt != null) {
try { stmt.close(); } catch (SQLException e) { ; }
stmt = null;
}
if (conn != null) {
try { conn.close(); } catch (SQLException e) { ; }
conn = null;
}
}
} |
Partager