diff --git a/src/de/steamwar/ImplementationProvider.java b/src/de/steamwar/ImplementationProvider.java index 1e8baec..e5b795e 100644 --- a/src/de/steamwar/ImplementationProvider.java +++ b/src/de/steamwar/ImplementationProvider.java @@ -28,7 +28,7 @@ public class ImplementationProvider { try { return (T) Class.forName(className).getDeclaredConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) { - throw new SecurityException("Could not load SQLConfigProviderImpl", e); + throw new SecurityException("Could not load implementation", e); } } } diff --git a/src/de/steamwar/sql/Statement.java b/src/de/steamwar/sql/Statement.java index 4ea6142..a1d55f0 100644 --- a/src/de/steamwar/sql/Statement.java +++ b/src/de/steamwar/sql/Statement.java @@ -64,11 +64,12 @@ public class Statement implements AutoCloseable { Connection connection; try { + Class.forName("org.sqlite.JDBC"); connection = DriverManager.getConnection("jdbc:sqlite:standalone.db"); - } catch (SQLException e) { + //TODO schema + } catch (SQLException | ClassNotFoundException e) { throw new SecurityException("Could not create sqlite connection", e); } - //TODO ensure schema conProvider = () -> connection; } @@ -117,14 +118,17 @@ public class Statement implements AutoCloseable { try { result = tryWithConnection(connection, runnable, objects); } catch (SQLException e) { - closeConnection(connection); - connection = aquireConnection(); try { - result = tryWithConnection(connection, runnable, objects); + if(connection.isClosed() || !connection.isValid(1)) { + closeConnection(connection); + return withConnection(runnable, objects); + } } catch (SQLException ex) { closeConnection(connection); - throw new SecurityException("Could not execute statement", ex); + throw new SecurityException("Could not test connection validity", ex); } + + throw new SecurityException("Failing sql statement", e); } synchronized (connections) {