Guest User

Untitled

a guest
Feb 18th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package me.florianb.systemesql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class SqlConnection {
  8.  
  9. private Connection connection;
  10. private String urlbase,host,database,user,pass;
  11.  
  12. public SqlConnection(String urlbase, String host, String database, String user, String pass) {
  13. this.urlbase = urlbase;
  14. this.host = host;
  15. this.database = database;
  16. this.user = user;
  17. this.pass = pass;
  18. }
  19.  
  20. public void connection(){
  21. if(!isConnected()){
  22. try {
  23. connection = DriverManager.getConnection(urlbase + host + "/" + database, user, pass);
  24. System.out.println("connected ok");
  25. } catch (SQLException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. }
  30.  
  31. public void disconnect(){
  32. if(isConnected()){
  33. try {
  34. connection.close();
  35. System.out.println("connected off");
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41.  
  42. public boolean isConnected(){
  43. return connection != null;
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment