diff --git a/src/main/java/de/epiceric/shopchest/sql/Database.java b/src/main/java/de/epiceric/shopchest/sql/Database.java index 154deb6..f7a085a 100644 --- a/src/main/java/de/epiceric/shopchest/sql/Database.java +++ b/src/main/java/de/epiceric/shopchest/sql/Database.java @@ -228,6 +228,11 @@ public abstract class Database { dataSource = getDataSource(); + if (dataSource == null) { + callback.onError(new SQLException("Failed to get data source")); + return; + } + try (Connection con = dataSource.getConnection()) { // Update database structure if necessary update(); diff --git a/src/main/java/de/epiceric/shopchest/sql/SQLite.java b/src/main/java/de/epiceric/shopchest/sql/SQLite.java index 01dbf9a..07dd334 100644 --- a/src/main/java/de/epiceric/shopchest/sql/SQLite.java +++ b/src/main/java/de/epiceric/shopchest/sql/SQLite.java @@ -20,6 +20,16 @@ public class SQLite extends Database { @Override HikariDataSource getDataSource() { + try { + // Initialize driver class so HikariCP can find it + Class.forName("org.sqlite.JDBC"); + } catch (ClassNotFoundException e) { + plugin.getLogger().severe("Failed to initialize SQLite driver"); + plugin.debug("Failed to initialize SQLite driver"); + plugin.debug(e); + return null; + } + File folder = plugin.getDataFolder(); File dbFile = new File(folder, "shops.db"); @@ -30,6 +40,7 @@ public class SQLite extends Database { plugin.getLogger().severe("Failed to create database file"); plugin.debug("Failed to create database file"); plugin.debug(ex); + return null; } }