Guest User

Untitled

a guest
Mar 28th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. private String hostname;
  2.  
  3. private Integer port;
  4.  
  5. private String username;
  6.  
  7. private String password;
  8.  
  9. private String database;
  10.  
  11. private Connection connection;
  12.  
  13. private Statement statement;
  14.  
  15. private ResultSet result;
  16.  
  17.  
  18. try
  19. {
  20. Class.forName("com.mysql.jdbc.Driver").newInstance();
  21. }
  22. catch (Exception ex)
  23. {
  24. System.out.println(ex.getMessage());
  25. }
  26. try
  27. {
  28.  
  29. this.connection = DriverManager.getConnection("jdbc:mysql://"+ this.getHostname() + "/" + this.getDatabase() + "?" +
  30. "user="+ this.getUsername() + "&password=" + this.getPassword());
  31. }
  32. catch (SQLException ex)
  33. {
  34. System.out.println("SQLException: " + ex.getMessage());
  35. System.out.println("SQLState: " + ex.getSQLState());
  36. System.out.println("VendorError: " + ex.getErrorCode());
  37. }
  38.  
  39.  
  40. try
  41. {
  42. this.statement = this.connection.createStatement());
  43.  
  44. if (this.statement.execute(query))
  45. {
  46. this.result = this.statement.getResultSet());
  47. }
  48. }
  49. catch (SQLException ex)
  50. {
  51. System.out.print(ex.getMessage());
  52. }
  53. finally
  54. {
  55.  
  56. }
Add Comment
Please, Sign In to add comment