WorldSystem/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java

44 lines
1.8 KiB
Java
Raw Normal View History

2019-04-22 16:47:36 +02:00
package de.butzlabben.world.util.database;
2019-04-22 14:32:01 +02:00
import de.butzlabben.world.config.PluginConfig;
2019-08-16 21:33:12 +02:00
import de.butzlabben.world.util.VersionUtil;
import org.bukkit.Bukkit;
2019-04-22 14:32:01 +02:00
2019-05-04 09:23:09 +02:00
import java.sql.DriverManager;
import java.sql.SQLException;
2019-08-16 21:33:12 +02:00
import java.util.logging.Level;
2019-04-22 14:32:01 +02:00
public class SqliteConnection extends DatabaseConnection {
2019-04-22 16:49:50 +02:00
private void connect(String file) {
2019-08-16 21:33:12 +02:00
if (VersionUtil.getVersion() <= 8) {
Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] ========================================================");
Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] SQLite is not available in 1.8.");
Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] Please consider using MySQL or disable the use_last_location option");
Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] ========================================================");
return;
}
2019-04-22 14:32:01 +02:00
synchronized (lock) {
try {
Class.forName("com.mysql.jdbc.Driver");
2019-08-16 21:33:12 +02:00
Class.forName("org.sqlite.JDBC");
2019-04-22 14:32:01 +02:00
} catch (ClassNotFoundException e) {
2019-08-16 21:33:12 +02:00
Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] Drivers are not working properly");
2019-04-22 14:32:01 +02:00
return;
}
try {
connection = DriverManager.getConnection("jdbc:sqlite:" + file);
2019-08-23 15:17:10 +02:00
Bukkit.getLogger().log(Level.INFO, "[WorldSystem | SQLite] Connected to local file database");
2019-04-22 14:32:01 +02:00
} catch (SQLException e) {
2019-08-16 21:33:12 +02:00
Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] Failed to connect with given server:");
2019-04-22 14:32:01 +02:00
e.printStackTrace();
}
}
}
public void connect() {
connect(PluginConfig.getSqliteFile());
}
}