Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4. import javax.swing.JOptionPane;
  5.  
  6. public abstract class DBConnection {
  7. private static Connection conn = null;
  8. public static Connection getInstance() {
  9. if(conn == null){
  10. try {
  11. Class.forName("com.mysql.jdbc.Driver");
  12. System.out.println("Driver O.K.");
  13. String url = "jdbc:mysql://localhost/nom_de_la_bd";
  14. String user = "root";
  15. String passwd = "";
  16. conn = DriverManager.getConnection(url, user, passwd);
  17. System.out.println("Connexion effective !");
  18.  
  19. } catch (ClassNotFoundException | SQLException e) {
  20. JOptionPane.showMessageDialog(null, "Erreur de communication avec la base de données!");
  21. }
  22. }
  23. return conn;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement