Advertisement
Guest User

Untitled

a guest
Jan 7th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package com.japanes.lobby;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. /**
  8. * Created by Gio on 23/12/2016.
  9. */
  10. public class SqlConnection {
  11.  
  12.  
  13. public static Connection connection;
  14. public static String urlbase,host,database,user,password;
  15.  
  16. public SqlConnection(String urlbase, String host, String database, String user, String password){
  17. this.urlbase=urlbase;
  18. this.host=host;
  19. this.database=database;
  20. this.user=user;
  21. this.password=password;
  22. }
  23.  
  24.  
  25. public void connection(){
  26. if(!isConnected()){
  27. try {
  28. connection = DriverManager.getConnection(urlbase+ host + "/" + database, user, password);
  29. System.out.println("[Sql]La connection entre le serveur et la base de donnée a été effectuée");
  30. }catch (SQLException e){
  31. e.printStackTrace();
  32. }
  33. }
  34. }
  35.  
  36.  
  37. public void disconnect(){
  38. try {
  39. connection.close();
  40. System.out.println("La base de donnée a été déconnectée.");
  41. }catch (SQLException e){
  42. e.printStackTrace();
  43. }
  44. }
  45.  
  46. public boolean isConnected(){
  47. return connection!=null;
  48. }
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement