initial commit
commit
c92292acbb
@ -0,0 +1,4 @@
|
||||
.DS_STORE
|
||||
.idea/
|
||||
Java SQL Interface.iml
|
||||
out/
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Interface">
|
||||
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="614" height="400"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-13882066"/>
|
||||
<enabled value="false"/>
|
||||
<font swing-font="MenuItem.font"/>
|
||||
<foreground color="-1"/>
|
||||
<toolTipText value="MySQL Query Tool"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="2660b" class="javax.swing.JTextArea" binding="queryInputField">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="280" height="220"/>
|
||||
<preferred-size width="280" height="220"/>
|
||||
<maximum-size width="280" height="220"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Query"/>
|
||||
<toolTipText value="Query"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="4341f">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="10"/>
|
||||
<preferred-size width="-1" height="10"/>
|
||||
<maximum-size width="-1" height="10"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="50a8e" class="javax.swing.JButton" binding="queryButton">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="290" height="30"/>
|
||||
<preferred-size width="290" height="30"/>
|
||||
<maximum-size width="290" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<foreground color="-12171706"/>
|
||||
<text value="Query"/>
|
||||
<toolTipText value="Query"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane id="c2654">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="280" height="220"/>
|
||||
<preferred-size width="280" height="220"/>
|
||||
<maximum-size width="280" height="220"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<foreground color="-1"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6de40" class="javax.swing.JTextArea" binding="queryOutputField">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<editable value="false"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Query Output"/>
|
||||
<toolTipText value="Query Output"/>
|
||||
<wrapStyleWord value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Login">
|
||||
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="52" y="20" width="625" height="356"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-13882066"/>
|
||||
<enabled value="false"/>
|
||||
<font swing-font="MenuItem.font"/>
|
||||
<foreground color="-1"/>
|
||||
<toolTipText value="MySQL Query Tool"/>
|
||||
</properties>
|
||||
<border type="none">
|
||||
<font swing-font="TextField.font"/>
|
||||
<title-color color="-1"/>
|
||||
<color color="-11888385"/>
|
||||
</border>
|
||||
<children>
|
||||
<component id="43282" class="javax.swing.JLabel" binding="image">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="6" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="4" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<foreground color="-1"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<icon value="images/icon.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1124" class="javax.swing.JTextField" binding="urlField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="200" height="-1"/>
|
||||
<preferred-size width="200" height="-1"/>
|
||||
<maximum-size width="200" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Database Url"/>
|
||||
<toolTipText value="Database Url"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b6ebe" class="javax.swing.JTextField" binding="usernameField">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="200" height="-1"/>
|
||||
<preferred-size width="200" height="-1"/>
|
||||
<maximum-size width="200" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Username"/>
|
||||
<toolTipText value="Username"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="8442" class="javax.swing.JPasswordField" binding="passwordField">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="200" height="-1"/>
|
||||
<preferred-size width="200" height="-1"/>
|
||||
<maximum-size width="200" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Password"/>
|
||||
<toolTipText value="Password"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="90b45" class="javax.swing.JButton" binding="submitButton">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="200" height="-1"/>
|
||||
<preferred-size width="200" height="-1"/>
|
||||
<maximum-size width="200" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-12171706"/>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-12171706"/>
|
||||
<text value="Login"/>
|
||||
<toolTipText value="Login"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="f8e37">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="60"/>
|
||||
<preferred-size width="-1" height="60"/>
|
||||
<maximum-size width="-1" height="60"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="73da6">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="55"/>
|
||||
<preferred-size width="-1" height="55"/>
|
||||
<maximum-size width="-1" height="55"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
Binary file not shown.
Loading…
Reference in New Issue