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
| /*
* DevisApp.java
*/
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException cnfe) {
System.out.println("Couldn't find the driver!");
System.out.println("Let's print a stack trace, and exit.");
// cnfe.printStackTrace();
System.exit(1);
}
Connection c = null;
try {
c = DriverManager.getConnection("jdbc:mysql://localhost:3306:reference","root", "root");
} catch (SQLException se) {
System.out.println("Nous ne pouvons pas nous connecter : affichage de l'erreur, puis sortie.");
//se.printStackTrace();
System.exit(1);
}
if (c != null) {
System.out.println("Hourra! Nous sommes connectés à la base de données");
/*Retourne un état permettant de réaliser une instruction simple*/
Statement st;
st = c.createStatement();
resultSet rs = st.executeQuery("SELECT prix_main_doeuvre prix_fourniture FROM prix_references_mur WHERE code_reference like INT001");
while (rs.next()) {
System.out.println("prix_main_doeuvre : "+rs.getDouble(1));
System.out.println("prix_fourniture : " +rs.getDouble(2));
}
rs.close();
st.close();
// Statement createStatement();
} else {
System.out.println("We should never get here.");
} |
Partager