Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Imports used throughout the class.
- */
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- import java.sql.ResultSet;
- /**
- * The SMFIntegration class.
- * @author Josh
- */
- public class SMFIntegration {
- /**
- * Connection instance to connect.
- */
- private static Connection con = null;
- /**
- * Open the connection for your database.
- */
- public static void connect() {
- try {
- System.out.println("Connecting to the Database.");
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection("jdbc:mysql://rs3newstart.tk/dbhere", "Rodrigues", "joshykins123");
- } catch (Exception e) {
- terminate();
- new NewStartException(e);
- }
- }
- /**
- * Question the statement with the question provided by the user.
- * @param question
- */
- public static boolean questionStatement(String question) {
- try {
- Statement state = con.createStatement();
- ResultSet rs = state.executeQuery(question);
- if (rs.next()) {
- state.close();
- return true;
- }
- state.close();
- } catch (Exception e) {
- terminate();
- new NewStartException(e);
- }
- return false;
- }
- /**
- * Terminate/end/delete the connection.
- */
- public static void terminate() {
- try {
- if (con != null) {
- con.close();
- }
- } catch (Exception e) {
- new NewStartException(e);
- }
- }
- /**
- * Integrate the server with the forums.
- */
- public static void integrateForums() {
- connect();
- System.out.println("Connected to the Database successfully.");
- }
- /**
- * Check the username and password and make sure they match up.
- * @param user
- * @param pass
- */
- public static boolean checkUsername(String user, String pass) {
- try {
- if (questionStatement("SELECT username FROM members WHERE username='" + user + "' AND password ='" + pass + "'")) {
- return true;
- }
- return false;
- } catch (Exception e) {
- System.out.println("Username or password seems to be incorrect or not found.");
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement