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
| public void Connect(){
new Thread(){
@Override
public void run(){
try {
Log.i("Debug","Driver initialisation...");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Log.i("Debug","Driver initialisé !");
}catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
Log.e("Debug",e.getMessage());
}
try{
Log.i("Debug","Connection à la BDD...");
con = DriverManager.getConnection(Url,"root","");
Log.i("Debug","Connecté à la BDD !");
Log.i("Debug","Recupération de la table...");
Statement st = con.createStatement();
String sql = ("SELECT * FROM `test`;");
ResultSet rs = st.executeQuery(sql);
if(rs.next()) {
Capteur1 = rs.getFloat("Capteur1");
Capteur2 = rs.getFloat("Capteur2");
Date = rs.getTimestamp("Date");
}
Log.i("Debug","Table récupéré!");;
rs.close();
st.close();
con.close();
} catch (SQLException e) {
Log.e("Debug",e.getMessage());
}
}
}.start();
} |
Partager