From 1b1e5de47e3811ec726749bcbbeab84e99fe54ff Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 16 Jun 2019 16:38:43 +0200 Subject: [PATCH] Initialize SQLite driver before use --- src/main/java/de/epiceric/shopchest/sql/Database.java | 5 +++++ src/main/java/de/epiceric/shopchest/sql/SQLite.java | 11 +++++++++++ 2 files changed, 16 insertions(+) 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; } }