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 class MySQL {
- private static Connection conn;
- public static void connectBDD() {
- try {
- conn = DriverManager.getConnection("jdbc:mysql://62.210.168.255:3306/elesia", "root", "ADMINSQL2017");
- JOptionPane.showMessageDialog(null, "Connexion réussi avec la base de données !", "ELESIA", JOptionPane.INFORMATION_MESSAGE);
- } catch (SQLException e) {
- JOptionPane.showMessageDialog(null, "La connexion à la base de données a échouée", "ELESIA", JOptionPane.WARNING_MESSAGE);
- e.printStackTrace();
- }
- }
- public static void disconnectBDD() {
- if (isConnected()) {
- try {
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- try {
- if ((conn == null) || (conn.isClosed()) || (conn.isValid(5))) {
- return false;
- }
- return true;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static Connection getConnection() {
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement