commit c92292acbb9701d2dd02ecd8b6790cc8a61fc6ee Author: The-Tysonator Date: Mon Apr 24 15:05:40 2023 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6452162 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_STORE +.idea/ +Java SQL Interface.iml +out/ \ No newline at end of file diff --git a/src/Database.java b/src/Database.java new file mode 100755 index 0000000..2e14c8f --- /dev/null +++ b/src/Database.java @@ -0,0 +1,59 @@ +// Imports +import java.sql.*; + +// Database Class +public class Database { + + // Variables + private Connection connection; + private Statement statement; + + // Setup Method + public void setup (String url, String username, String password) throws SQLException { + // Set Variables + this.connection = DriverManager.getConnection(url, username, password); + this.statement = this.connection.createStatement(); + } + + // Is Setup Method + public boolean isSetup () { + // Return Setup + return this.connection != null && this.statement != null; + } + + // Query Method + public String query (String sql) { + // Catch Errors + try { + // Execute Query + ResultSet results = this.statement.executeQuery(sql); + ResultSetMetaData resultsMetaData = results.getMetaData(); + // Create Result + StringBuilder result = new StringBuilder(); + // Create Header + for (int counter = 1; counter <= resultsMetaData.getColumnCount(); counter++) { + result.append(resultsMetaData.getColumnName(counter)); + if (counter != resultsMetaData.getColumnCount()) { + result.append(" - "); + } + } + result.append("\n"); + // Create Content + while (results.next()) { + for (int counter = 1; counter <= resultsMetaData.getColumnCount(); counter++) { + result.append(results.getString(counter)); + if (counter != resultsMetaData.getColumnCount()) { + result.append(" - "); + } + } + result.append("\n"); + } + // Return Result + return result.toString(); + } catch (Exception exception) { + // Return Result + return "Query Invalid"; + } + } + +} \ No newline at end of file diff --git a/src/Interface.form b/src/Interface.form new file mode 100755 index 0000000..f7bc6b5 --- /dev/null +++ b/src/Interface.form @@ -0,0 +1,85 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Interface.java b/src/Interface.java new file mode 100755 index 0000000..6966005 --- /dev/null +++ b/src/Interface.java @@ -0,0 +1,38 @@ +// Imports +import javax.swing.*; + +// Interface Class +public class Interface extends JFrame { + + // Components + private JPanel panel; + private JTextArea queryInputField; + private JTextArea queryOutputField; + private JButton queryButton; + + // Interface Method + public Interface(Database database) { + // Create Windows + setTitle("MySQL Query Tool"); + setResizable(false); + setSize(600, 300); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setContentPane(panel); + setVisible(true); + // Query Button Clicked + queryButton.addActionListener( e -> { + // Update Button + queryButton.setText("Querying"); + // Get Query + String query = queryInputField.getText(); + try { + queryOutputField.setText(database.query(query)); + } catch (Exception ex) { + queryOutputField.setText("Error"); + } + // Update Button + queryButton.setText("Query"); + }); + } + +} \ No newline at end of file diff --git a/src/Login.form b/src/Login.form new file mode 100755 index 0000000..86efaef --- /dev/null +++ b/src/Login.form @@ -0,0 +1,116 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Login.java b/src/Login.java new file mode 100755 index 0000000..ad61467 --- /dev/null +++ b/src/Login.java @@ -0,0 +1,43 @@ +// Imports +import javax.swing.*; + +// Login Class +public class Login extends JFrame { + + // Components + private JPanel panel; + private JLabel image; + private JTextField urlField; + private JTextField usernameField; + private JPasswordField passwordField; + private JButton submitButton; + + // Login Method + public Login(Database database) { + // Create Window + setTitle("MySQL Query Tool"); + setResizable(false); + setSize(600, 300); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setContentPane(panel); + setVisible(true); + // Submit Button Clicked + submitButton.addActionListener( e -> { + // Update Button + submitButton.setText("Connecting"); + // Get Field Data + String url = urlField.getText(); + String username = usernameField.getText(); + String password = passwordField.getText(); + // Create Connection + try { + database.setup("jdbc:mysql://" + url, username, password); + setVisible(false); + dispose(); + } catch (Exception exception) { + submitButton.setText("Login"); + } + }); + } + +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100755 index 0000000..55ab9a6 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,18 @@ +// Main Class +public class Main { + + // Database + public static Database database = new Database(); + + // Main Method + public static void main (String []args) { + // Login + new Login(database); + while (!database.isSetup()) { + System.out.println(database.isSetup()); + } + // Interface + new Interface(database); + } + +} \ No newline at end of file diff --git a/src/images/icon.png b/src/images/icon.png new file mode 100755 index 0000000..8e7db8b Binary files /dev/null and b/src/images/icon.png differ diff --git a/src/jar/mysql-connector-java-8.0.25.jar b/src/jar/mysql-connector-java-8.0.25.jar new file mode 100755 index 0000000..3db626b Binary files /dev/null and b/src/jar/mysql-connector-java-8.0.25.jar differ