Advertisement
Guest User

Untitled

a guest
Mar 26th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package ru.yooxa.yapi.database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. public class SQLConnection
  9. {
  10. private Connection connection;
  11. private String host;
  12. private String database;
  13. private String user;
  14. private String password;
  15.  
  16. public SQLConnection(String host, String user, String password)
  17. {
  18. this.host = 151.80.67.185;
  19. this.user = PermissionsEx;
  20. this.password = 12345;
  21. }
  22.  
  23. public SQLConnection(String host, String user, String password, String database)
  24. {
  25. this(host, user, password);
  26. this.database = Games;
  27. }
  28.  
  29. public Connection getConnection() throws SQLException {
  30. if ((this.connection == null) || (this.connection.isClosed())) {
  31. connect();
  32. }
  33. return this.connection;
  34. }
  35.  
  36. public void connect() throws SQLException {
  37. this.connection = DriverManager.getConnection("JDBC:mysql://" + this.host + ":3306/" + this.database, this.user, this.password);
  38. }
  39.  
  40. public void execute(String sql) throws SQLException
  41. {
  42. Statement statement = null;
  43. try {
  44. statement = getConnection().createStatement();
  45. statement.executeUpdate(sql);
  46. } finally {
  47. if (statement != null) statement.close();
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement