Guest User

Untitled

a guest
Mar 4th, 2018
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package com.servercontrol.sql;
  2.  
  3. import com.servercontrol.ServerControl;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8.  
  9. public class SqlConnection {
  10.  
  11. private Connection con;
  12. private String urlbase,host,database,user,password;
  13.  
  14.  
  15. public SqlConnection(String urlbase, String host, String database, String user, String password){
  16. this.urlbase = urlbase;
  17. this.host = host;
  18. this.database = database;
  19. this.user = user;
  20. this.password = password;
  21. }
  22.  
  23. public void connect(){
  24. if(!isConnected()) {
  25. try {
  26. con = DriverManager.getConnection(urlbase + host + "/" + database, user, password);
  27.  
  28. if(ServerControl.getInstance().getConfig().getBoolean("config.lang.fr") == true) {
  29. ServerControl.getInstance().getServer().getConsoleSender().sendMessage(
  30. ServerControl.getInstance().getConfig().getString("config.messages.fr.server_connected_database"));
  31. }
  32. } catch (SQLException e) {e.printStackTrace();}
  33. }
  34. }
  35.  
  36. public void disconnect(){
  37. if(isConnected()) {
  38. try {
  39. con.close();
  40.  
  41. } catch (SQLException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. }
  46.  
  47. private boolean isConnected(){
  48. return con != null;
  49. }
  50. }
Add Comment
Please, Sign In to add comment