Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- public abstract class DBConnection {
- private static Connection conn = null;
- public static Connection getInstance() {
- if(conn == null){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Driver O.K.");
- String url = "jdbc:mysql://localhost/nom_de_la_bd";
- String user = "root";
- String passwd = "";
- conn = DriverManager.getConnection(url, user, passwd);
- System.out.println("Connexion effective !");
- } catch (ClassNotFoundException | SQLException e) {
- JOptionPane.showMessageDialog(null, "Erreur de communication avec la base de données!");
- }
- }
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement