Advertisement
DeveloperSergio

class ConnectDB

Dec 6th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. package login;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. /**
  8. * Created by Admin on 02.12.2016.
  9. */
  10. public class ConnectDB {
  11.  
  12.  
  13. private Connection connection;
  14.  
  15. private String message = "";
  16.  
  17. // возвращаем геттер с коннектом
  18. public Connection getConnection(){
  19. return connection;
  20. }
  21.  
  22. public String getMessage(){
  23. return message;
  24. }
  25.  
  26. public boolean conDB(String URL, String USER, String PASS){
  27.  
  28. boolean flag;
  29.  
  30. try {
  31.  
  32. connection = DriverManager.getConnection(URL, USER, PASS);
  33.  
  34. } catch (SQLException e) {
  35. message = "Connection Failed";
  36. flag = false;
  37. // e.printStackTrace();
  38. }
  39.  
  40. if (connection != null) {
  41. message = "Successfully Connected";
  42. flag = true;
  43. } else {
  44. message = "Connection Failed";
  45. flag = false;
  46. }
  47.  
  48. return flag;
  49. }
  50.  
  51.  
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement