Initialize SQLite driver before use

This commit is contained in:
Eric 2019-06-16 16:38:43 +02:00
parent 341c17b047
commit 1b1e5de47e
2 changed files with 16 additions and 0 deletions

View File

@ -228,6 +228,11 @@ public abstract class Database {
dataSource = getDataSource(); dataSource = getDataSource();
if (dataSource == null) {
callback.onError(new SQLException("Failed to get data source"));
return;
}
try (Connection con = dataSource.getConnection()) { try (Connection con = dataSource.getConnection()) {
// Update database structure if necessary // Update database structure if necessary
update(); update();

View File

@ -20,6 +20,16 @@ public class SQLite extends Database {
@Override @Override
HikariDataSource getDataSource() { 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 folder = plugin.getDataFolder();
File dbFile = new File(folder, "shops.db"); 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.getLogger().severe("Failed to create database file");
plugin.debug("Failed to create database file"); plugin.debug("Failed to create database file");
plugin.debug(ex); plugin.debug(ex);
return null;
} }
} }