Guest User

Untitled

a guest
Jan 4th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package bdd;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class MaBdd {
  8.  
  9. static String url = "jdbc:mysql://localhost:3306/m2i"; // url de ma base de donnee
  10. static String user = "root";
  11. static String password = "";
  12. static Connection connexion = null;
  13.  
  14. public static Connection LoadDatabase() {
  15. try {
  16. Class.forName("com.mysql.jdbc.Driver");
  17. } catch (ClassNotFoundException e) {
  18. System.out.println(e.getMessage());
  19. }
  20. try {
  21. connexion = DriverManager.getConnection(url, user, password);
  22. return connexion;
  23.  
  24. } catch (SQLException e) {
  25. e.printStackTrace();
  26. }
  27. return null;
  28.  
  29. }
  30.  
  31. static void CloseDatabase() {
  32.  
  33. try {
  34. connexion.close();
  35. } catch (SQLException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. }
  39.  
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment