Dieser Commit ist enthalten in:
Ursprung
84eba0a156
Commit
2e528918bb
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
|
import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
@ -33,9 +34,9 @@ public class SQL {
|
|||||||
private SQL(){}
|
private SQL(){}
|
||||||
|
|
||||||
private static Connection con;
|
private static Connection con;
|
||||||
private static String url;
|
private static final String URL;
|
||||||
private static String user;
|
private static final String USER;
|
||||||
private static String password;
|
private static final String PASSWORD;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
File file = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
File file = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
||||||
@ -44,16 +45,16 @@ public class SQL {
|
|||||||
if(!file.exists())
|
if(!file.exists())
|
||||||
throw new SecurityException("SQL-ConfigFile not found!");
|
throw new SecurityException("SQL-ConfigFile not found!");
|
||||||
|
|
||||||
url = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE");
|
URL = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE");
|
||||||
user = config.getString("USER");
|
USER = config.getString("USER");
|
||||||
password = config.getString("PASSWORD");
|
PASSWORD = config.getString("PASSWORD");
|
||||||
|
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void connect() {
|
private static void connect() {
|
||||||
try {
|
try {
|
||||||
con = DriverManager.getConnection(url + "?autoReconnect=true&useServerPrepStmts=true", user, password);
|
con = DriverManager.getConnection(URL + "?useServerPrepStmts=true", USER, PASSWORD);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SecurityException("Could not start SQL connection", e);
|
throw new SecurityException("Could not start SQL connection", e);
|
||||||
}
|
}
|
||||||
@ -96,6 +97,7 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
static void update(String qry, Object... objects) {
|
static void update(String qry, Object... objects) {
|
||||||
try {
|
try {
|
||||||
prepare(qry, objects).executeUpdate();
|
prepare(qry, objects).executeUpdate();
|
||||||
@ -105,6 +107,7 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
static ResultSet select(String qry, Object... objects) {
|
static ResultSet select(String qry, Object... objects) {
|
||||||
try {
|
try {
|
||||||
return prepare(qry, objects).executeQuery();
|
return prepare(qry, objects).executeQuery();
|
||||||
@ -114,6 +117,7 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
static Blob blob() {
|
static Blob blob() {
|
||||||
try {
|
try {
|
||||||
return con.createBlob();
|
return con.createBlob();
|
||||||
@ -123,6 +127,7 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private static PreparedStatement prepare(String qry, Object... objects) throws SQLException {
|
private static PreparedStatement prepare(String qry, Object... objects) throws SQLException {
|
||||||
PreparedStatement st = con.prepareStatement(qry);
|
PreparedStatement st = con.prepareStatement(qry);
|
||||||
for(int i = 0; i < objects.length; i++){
|
for(int i = 0; i < objects.length; i++){
|
||||||
@ -168,8 +173,10 @@ public class SQL {
|
|||||||
try {
|
try {
|
||||||
setObjects(objects);
|
setObjects(objects);
|
||||||
return runnable.run();
|
return runnable.run();
|
||||||
} catch (SQLException e) {
|
} catch (CommunicationsException e) {
|
||||||
reset();
|
reset();
|
||||||
|
return prepare(runnable, objects);
|
||||||
|
} catch (SQLException e) {
|
||||||
throw new SecurityException("Could not execute SQL statement", e);
|
throw new SecurityException("Could not execute SQL statement", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren