Aust1n46 d7858a791a Fixed SQL injection vulnerability in the MySQL logging feature. Using
Hikari library to automatically reconnect to database. Thanks to
metalshark setting this up.
2020-03-25 17:44:03 -04:00

34 lines
1.0 KiB
Java

package mineverse.Aust1n46.chat.database;
import java.io.File;
import java.io.IOException;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import mineverse.Aust1n46.chat.MineverseChat;
//This class initializes the connection to a SQLite database, which has no implementations currently in the plugin.
public class SQLite extends Database {
private final String dbLocation;
public SQLite(String dbLocation) {
this.dbLocation = dbLocation;
}
@Override
public void init() {
File dataFolder = MineverseChat.getInstance().getDataFolder();
if (!dataFolder.exists()) dataFolder.mkdirs();
File databaseFile = new File(dataFolder, dbLocation);
try {
if (!databaseFile.exists()) databaseFile.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
HikariConfig config = new HikariConfig();
final String jdbcUrl = String.format("jdbc:sqlite:%s", databaseFile);
config.setJdbcUrl(jdbcUrl);
dataSource = new HikariDataSource(config);
}
}