Advertisement
Fosco_dev

Bdd.java

Jun 27th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class Bdd {
  2.  
  3. String url;
  4. String user;
  5. String databaseName;
  6. String passwd;
  7.  
  8.  
  9. Connection conn = null; Statement st = null; ResultSet rs = null;
  10.  
  11.  
  12. public Bdd() {
  13.  
  14. }
  15.  
  16. public Bdd(String purl, String puser, String ppasswd, String pdatabaseName) {
  17. this.url = purl;
  18. this.user = puser;
  19. this.passwd = ppasswd;
  20. this.databaseName = pdatabaseName;
  21. }
  22.  
  23. public void Connection(){
  24.  
  25. try {
  26. Class.forName("com.mysql.jdbc.Driver");
  27. System.out.println("Driver O.K.");
  28. conn = DriverManager.getConnection("jdbc:mysql://"
  29. + this.url
  30. + ":3306/"
  31. + this.databaseName, this.user, this.passwd);
  32. System.out.println("Connexion effective !");
  33.  
  34. } catch (Exception e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. public void Disconnect(){
  40. try {
  41. conn.close();
  42. System.out.println("Déconnection éffectué");
  43. } catch (SQLException e) {
  44. e.printStackTrace();
  45. }
  46. }
  47.  
  48. public void getDonnees(){
  49. try{
  50. st = conn.createStatement();
  51.  
  52. rs = st.executeQuery("SELECT * FROM Metarduino ORDER BY Id");
  53.  
  54. while (rs.next()) {
  55. System.out.println(rs.getInt("Temperature"));
  56. }
  57. }catch (Exception e) {
  58. e.printStackTrace();
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement