diff --git a/README.md b/README.md index f5f9a81..4e4b17a 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ _To get started you can download a sample file from sqlitetutorial.net [here](ht - SQLite ## Roadmap -I plan on adding support for more SQL-flavours such as PostgresQL, MySQL and MSSQL in the future. +I plan on adding support for more SQL-flavours such as MySQL & MSSQL in the future. diff --git a/app/res/screenshot-viewer.png b/app/res/screenshot-viewer.png index c69acd2..c067a4e 100644 Binary files a/app/res/screenshot-viewer.png and b/app/res/screenshot-viewer.png differ diff --git a/app/src/main/java/SQLite/Viewer/Driver.java b/app/src/main/java/SQLite/Viewer/Driver.java index e80ccd5..212c7bf 100644 --- a/app/src/main/java/SQLite/Viewer/Driver.java +++ b/app/src/main/java/SQLite/Viewer/Driver.java @@ -11,19 +11,20 @@ public class Driver implements AutoCloseable { private Connection connection; + private static String url; + // Queries public static final String SQL_ALL_ROWS = "SELECT * FROM %s;"; private static final String SQL_FIND_ALL_TABLES = "SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%';"; public Driver(String fileName) throws SQLException { + setUrl(); connect(fileName); } // Connect to a selected database protected void connect(String fileName) throws SQLException { - // SQLite default url - String url = "jdbc:sqlite:%s"; SQLiteDataSource dataSource = new SQLiteDataSource(); dataSource.setUrl(String.format(url, fileName)); connection = dataSource.getConnection(); @@ -67,6 +68,11 @@ protected DataTableModel runQuery(String query, String table) throws SQLExceptio } } + private void setUrl() { + // Currently, only sqlite is supported + url = "jdbc:sqlite:%s"; + } + @Override public void close() throws Exception { connection.close(); diff --git a/app/src/main/java/SQLite/Viewer/SQLiteViewer.java b/app/src/main/java/SQLite/Viewer/SQLiteViewer.java index f9ce73d..6ba4cf7 100644 --- a/app/src/main/java/SQLite/Viewer/SQLiteViewer.java +++ b/app/src/main/java/SQLite/Viewer/SQLiteViewer.java @@ -16,9 +16,9 @@ public class SQLiteViewer extends JFrame { public SQLiteViewer() { // Basic window settings setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setSize(595, 700); + setSize(540, 700); setLayout(new BorderLayout()); - setResizable(true); + setResizable(false); setLocationRelativeTo(null); setTitle("SQLite Viewer"); // Initialize main window components @@ -41,8 +41,8 @@ private void initComponents() { JTextArea queryTextArea = new JTextArea(); queryTextArea.setName("QueryTextArea"); - queryTextArea.setRows(5); - queryTextArea.setColumns(40); + queryTextArea.setRows(8); + queryTextArea.setColumns(35); queryTextArea.setEnabled(false); JScrollPane queryTextScroll = new JScrollPane(queryTextArea); @@ -70,9 +70,7 @@ private void initComponents() { JMenuItem quitMenuItem = new JMenuItem("Quit"); quitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx())); - quitMenuItem.addActionListener(actionEvent -> { - System.exit(0); - }); + quitMenuItem.addActionListener(actionEvent -> System.exit(0)); quitMenuItem.setName("MenuExit"); // Add file menu components @@ -83,7 +81,8 @@ private void initComponents() { // SQL selection menu JMenu sqlMenu = new JMenu("Select"); - JMenuItem sqliteMenuItem = new JMenuItem("SQLite"); + JCheckBoxMenuItem sqliteMenuItem = new JCheckBoxMenuItem("SQLite"); + sqliteMenuItem.setState(true); sqlMenu.add(sqliteMenuItem); @@ -164,9 +163,8 @@ private void initComponents() { ); } }); - tablesComboBox.addItemListener(actionEvent -> { - queryTextArea.setText(String.format(Driver.SQL_ALL_ROWS, actionEvent.getItem().toString())); - }); + tablesComboBox.addItemListener(actionEvent -> + queryTextArea.setText(String.format(Driver.SQL_ALL_ROWS, actionEvent.getItem().toString()))); executeButton.addActionListener(actionEvent -> { try (Driver driver = new Driver(fileNameTextField.getText())) { DataTableModel tableModel = driver.runQuery(