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
|
Connection connexion = null;
Statement instruction = null;
ResultSet resultat = null;
try {
connexion = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "estest");
try {
instruction = connexion.createStatement();
try {
resultat = instruction
.executeQuery("SELECT col1 FROM table1");
try {
while (resultat.next()) {
System.out.println("Resultat: "
+ resultat.getString("col1"));
}
} catch (SQLException e) {
throw e;
} finally {
resultat.close();
}
} catch (SQLException e) {
throw e;
} finally {
instruction.close();
}
} catch (SQLException e) {
throw e;
} finally {
connexion.close();
}
} catch (SQLException e) {
System.out.println("echec pilote : " + e);
} |
Partager