Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SQL {
- private static Connection conn;
- public static void connect(String host, String database, int port, String user, String password)
- {
- if (!isConnected())
- try {
- conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
- System.out.println("Connexion etablie avec la base de donnees");
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.println("Connexion refuse avec la base de donnees");
- }
- }
- public static void disconnect()
- {
- 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