Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.toundrake.faveur;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class SQLConnection {
- private Connection connection;
- private String urlbase, sQLHost, sQLName, sQLUser, sQLPass;
- public SQLConnection(String urlbase, String sQLHost, String sQLName, String sQLUser, String sQLPass) {
- this.urlbase = urlbase;
- this.sQLHost = sQLHost;
- this.sQLName = sQLName;
- this.sQLUser = sQLUser;
- this.sQLPass = sQLPass;
- }
- public void connect(){
- if(!isConnected()){
- try {
- System.out.println(urlbase + sQLHost + "/" + sQLName + sQLUser + sQLPass);
- connection = DriverManager.getConnection(urlbase + sQLHost + "/" + sQLName, sQLUser, sQLPass);
- System.out.println("Connection effectuée");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.out.println("arf, il y a un problème de connexion à la base SQL");
- }
- }
- }
- public void disconnect(){
- if(isConnected()){
- try {
- connection.close();
- System.out.println("Déconnexion effectuée");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public boolean isConnected(){
- return connection != null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement