Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. Code of connecting
  2. Code of connecting
  3.  
  4. private Connection connection;
  5. public void mysqlSetup() {
  6. String host = "us-cdbr-iron-east-01.cleardb.net";
  7. int port = 3306;
  8. String database = "null";
  9. String username = "null";
  10. String password = "null";
  11. try {
  12. synchronized (this) {
  13. if (getConnection() != null && !getConnection().isClosed()) {
  14. return;
  15. }
  16. Class.forName("com.mysql.cj.jdbc.Driver");
  17. setConnection(
  18. DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password));
  19. }
  20. } catch (SQLException | ClassNotFoundException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24.  
  25.  
  26.  
  27.  
  28. Code of editing
  29. Code of editing
  30.  
  31. public boolean maintenance() {
  32. try {
  33. PreparedStatement statement = getConnection()
  34. .prepareStatement("SELECT * FROM maintenance WHERE status=?");
  35. statement.setString(1, "stats");
  36. ResultSet results = statement.executeQuery();
  37. results.next();
  38. int returnvalue = results.getInt("id");
  39. results.close();
  40. statement.close();
  41. return returnvalue != 0;
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. return true;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement