Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /**
  2. * Imports used throughout the class.
  3. */
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.Statement;
  7. import java.sql.ResultSet;
  8.  
  9. /**
  10. * The SMFIntegration class.
  11. * @author Josh
  12. */
  13. public class SMFIntegration {
  14.  
  15. /**
  16. * Connection instance to connect.
  17. */
  18. private static Connection con = null;
  19.  
  20. /**
  21. * Open the connection for your database.
  22. */
  23. public static void connect() {
  24. try {
  25. System.out.println("Connecting to the Database.");
  26. Class.forName("com.mysql.jdbc.Driver").newInstance();
  27. con = DriverManager.getConnection("jdbc:mysql://rs3newstart.tk/dbhere", "Rodrigues", "joshykins123");
  28. } catch (Exception e) {
  29. terminate();
  30. new NewStartException(e);
  31. }
  32. }
  33.  
  34. /**
  35. * Question the statement with the question provided by the user.
  36. * @param question
  37. */
  38. public static boolean questionStatement(String question) {
  39. try {
  40. Statement state = con.createStatement();
  41. ResultSet rs = state.executeQuery(question);
  42. if (rs.next()) {
  43. state.close();
  44. return true;
  45. }
  46. state.close();
  47. } catch (Exception e) {
  48. terminate();
  49. new NewStartException(e);
  50. }
  51. return false;
  52. }
  53.  
  54. /**
  55. * Terminate/end/delete the connection.
  56. */
  57. public static void terminate() {
  58. try {
  59. if (con != null) {
  60. con.close();
  61. }
  62. } catch (Exception e) {
  63. new NewStartException(e);
  64. }
  65. }
  66.  
  67. /**
  68. * Integrate the server with the forums.
  69. */
  70. public static void integrateForums() {
  71. connect();
  72. System.out.println("Connected to the Database successfully.");
  73. }
  74.  
  75. /**
  76. * Check the username and password and make sure they match up.
  77. * @param user
  78. * @param pass
  79. */
  80. public static boolean checkUsername(String user, String pass) {
  81. try {
  82. if (questionStatement("SELECT username FROM members WHERE username='" + user + "' AND password ='" + pass + "'")) {
  83. return true;
  84. }
  85. return false;
  86. } catch (Exception e) {
  87. System.out.println("Username or password seems to be incorrect or not found.");
  88. return false;
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement