grundlegente Umstellung + Earthdawn Implemntation

This commit is contained in:
Ocame
2025-07-06 16:22:48 +02:00
parent 10c8c9900f
commit e2b9694e09
48 changed files with 1488 additions and 638 deletions

View File

@ -0,0 +1,93 @@
package de.ocame.wuerfelbot.DB;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class base {
private Connection conn;
private String typ;
private String host;
private String port;
private String database;
private String name;
private String pw;
private boolean active;
protected base() {
FileInputStream input = null;
Properties config = new Properties();
active = true;
try {
input = new FileInputStream("shadowrun.cfg");
config.load(input);
if(!config.containsKey("db.typ") || (config.containsKey("db.on") && !config.getProperty("db.on").equals("true"))) {
active = false;
}
typ = config.getProperty("db.typ");
host = config.getProperty("db.host");
port = config.getProperty("db.port");
database = config.getProperty("db.database");
name = config.getProperty("db.name");
pw = config.getProperty("db.pw");
open();
close();
//rs.fetchSize;
}
catch (Exception e) {
active = false;
}
}
protected void open() {
if(!active)
return;
try {
conn = DriverManager.getConnection("jdbc:" + typ + "://" + host + ":" + port + "?useUnicode=true&characterEncoding=utf-8", name, pw);
ResultSet rs = conn.prepareStatement("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" + database + "'").executeQuery();
rs.last();
if(rs.getRow() == 1) {
conn.prepareStatement("use "+ database).executeQuery();
}
}
catch (SQLException e) {
active = false;
//e.printStackTrace();
}
}
protected void close() {
if(!active)
return;
try {
if (!conn.isClosed())
conn.close();
}
catch (SQLException e) {
active = false;
e.printStackTrace();
}
}
protected boolean isActive() {
return active;
}
protected Connection getConn() {
return conn;
}
}