I am using a Java GUI program to update a SQlite database. My Gui options are mostly toggle buttons with on/off values. Due to the nature of the Gui, performance in updating the database needs to be fast so control can be returned to the Gui calling function quickly.
I have the following code, which runs every time a toggle button is selected:
public static void updateDCStable(String item, int value) { try { long start = System.currentTimeMillis(); Class.forName("org.sqlite.JDBC"); String url = DATABASE_FILEPATH; Connection conn = DriverManager.getConnection(url); Statement update = conn.createStatement(); update.execute("UPDATE DCS " + "SET " + item + "='" + value + "';"); update.close(); conn.close(); long time_elapsed = System.currentTimeMillis() - start; System.out.println("Changed DCS date item " + item + " to " + value + " in " + time_elapsed + "(ms)"); } catch (SQLException ex) { /* Error handling */ } catch (ClassNotFoundException ex) { /* Error handling */ } } My SQL table is basically configuration info with several columns and just one row, so the function takes the column and the update value and updates the item accordingly. The function works correctly, its just really slow....
Using the time elapsed, my average update time is running about 550 ms or so with a min time of 294 ms and a max time of 986 ms. Is there any way that I can speed up this process?