Code:
package DuB.lv;
import com.google.common.collect.ImmutableMap;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;
import java.util.logging.Logger;
public class Database
{
private String user;
private String pass;
private String url;
public Logger log;
private Connection connection;
private BungeePortals plugin;
private boolean queryInProgress;
private ImmutableMap<String, String> tables;
public Database(String user, String pass, String url, BungeePortals instance, Map<String, String> tables)
{
this.queryInProgress = false;
this.user = user;
this.pass = pass;
this.url = url;
this.plugin = instance;
this.tables = ImmutableMap.copyOf(tables);
}
private boolean initialize() {
try {
Class.forName("com.mysql.jdbc.Driver");
return true;
} catch (ClassNotFoundException e) {
this.plugin.getLogger().severe("MySQL driver class missing: " + e.getMessage() + ".");
}return false;
}
public String getTable(String name)
{
return (String)this.tables.get(name);
}
public boolean checkConnection() {
if (open() == null)
return false;
return true;
}
public Connection open() {
if (!initialize())
return null;
try {
if (this.connection == null)
return DriverManager.getConnection(this.url, this.user, this.pass);
if (this.connection.isValid(3)) {
return this.connection;
}
return DriverManager.getConnection(this.url, this.user, this.pass);
}
catch (SQLException e) {
this.plugin.getLogger().severe(this.url);
this.plugin.getLogger().severe("Could not be resolved because of an SQL Exception: " + e.getMessage() + ".");
}
return null;
}
public void close() {
if (this.queryInProgress) {
return;
}
this.connection = open();
try {
if (this.connection != null) {
this.connection.close();
this.connection = null;
}
} catch (Exception e) {
this.plugin.getLogger().severe("Failed to close database connection: " + e.getMessage());
}
}
public ResultSet query(String query) {
Statement statement = null;
ResultSet result = null;
this.queryInProgress = true;
try {
this.connection = open();
statement = this.connection.createStatement();
switch (1.$SwitchMap$DuB$lv$BungeePortals$Database$Statements[getStatement(query).ordinal()]) {
case 1:
result = statement.executeQuery(query);
this.queryInProgress = false;
return result;
}
statement.executeUpdate(query);
this.queryInProgress = false;
return result;
}
catch (SQLException e) {
this.plugin.getLogger().warning("Error in SQL query: " + e.getMessage());
this.plugin.getLogger().warning(query);
}
return result;
}
public int updateQuery(String query) {
Connection connection = null;
Statement statement = null;
try {
connection = open();
statement = connection.createStatement();
return statement.executeUpdate(query);
}
catch (SQLException e) {
this.plugin.getLogger().warning("Error in SQL query: " + e.getMessage());
this.plugin.getLogger().warning(query);
}
return 0;
}
public PreparedStatement prepare(String query) {
Connection connection = null;
PreparedStatement ps = null;
try {
connection = open();
return connection.prepareStatement(query);
}
catch (SQLException e) {
if (!e.toString().contains("not return ResultSet")) {
this.plugin.getLogger().warning("Error in SQL prepare() query: " + e.getMessage());
this.plugin.getLogger().warning(query);
}
}
return ps;
}
protected Statements getStatement(String query) {
String trimmedQuery = query.trim();
if (trimmedQuery.substring(0, 6).equalsIgnoreCase("SELECT"))
return Statements.SELECT;
if (trimmedQuery.substring(0, 6).equalsIgnoreCase("INSERT"))
return Statements.INSERT;
if (trimmedQuery.substring(0, 6).equalsIgnoreCase("UPDATE"))
return Statements.UPDATE;
if (trimmedQuery.substring(0, 6).equalsIgnoreCase("DELETE"))
return Statements.DELETE;
if (trimmedQuery.substring(0, 6).equalsIgnoreCase("CREATE"))
return Statements.CREATE;
if (trimmedQuery.substring(0, 5).equalsIgnoreCase("ALTER"))
return Statements.ALTER;
if (trimmedQuery.substring(0, 4).equalsIgnoreCase("DROP"))
return Statements.DROP;
if (trimmedQuery.substring(0, 8).equalsIgnoreCase("TRUNCATE"))
return Statements.TRUNCATE;
if (trimmedQuery.substring(0, 6).equalsIgnoreCase("RENAME"))
return Statements.RENAME;
if (trimmedQuery.substring(0, 2).equalsIgnoreCase("DO"))
return Statements.DO;
if (trimmedQuery.substring(0, 7).equalsIgnoreCase("REPLACE"))
return Statements.REPLACE;
if (trimmedQuery.substring(0, 4).equalsIgnoreCase("LOAD"))
return Statements.LOAD;
if (trimmedQuery.substring(0, 7).equalsIgnoreCase("HANDLER"))
return Statements.HANDLER;
if (trimmedQuery.substring(0, 4).equalsIgnoreCase("CALL")) {
return Statements.CALL;
}
return Statements.SELECT;
}
public boolean createTable(String query) {
Statement statement = null;
try {
this.connection = open();
if ((query.equals("")) || (query == null)) {
this.plugin.getLogger().severe("SQL query empty: createTable(" + query + ")");
return false;
}
statement = this.connection.createStatement();
statement.execute(query);
return true;
} catch (SQLException e) {
this.plugin.getLogger().severe(e.getMessage());
return false;
} catch (Exception e) {
this.plugin.getLogger().severe(e.getMessage());
}return false;
}
public boolean checkTable(String table)
{
try {
this.connection = open();
if (this.connection == null) {
this.plugin.getLogger().severe("Unable to check if tables exist");
return false;
}
Statement statement = this.connection.createStatement();
ResultSet result = statement.executeQuery("SELECT * FROM " + table);
if (result == null)
return false;
if (result != null)
return true;
} catch (SQLException e) {
if (e.getMessage().contains("exist")) {
return false;
}
this.plugin.getLogger().info("Error in SQL query: " + e.getMessage());
}
if (query("SELECT * FROM " + table) == null)
return true;
return false;
}
public boolean colExists(String table, String column) {
try {
this.connection = open();
if (this.connection == null) {
this.plugin.getLogger().severe("Unable to check if tables exist");
return false;
}
DatabaseMetaData metadata = this.connection.getMetaData();
ResultSet result = metadata.getColumns(null, null, table, column);
if (result == null)
return false;
if ((result != null) &&
(result.next())) {
result.close();
return true;
}
}
catch (SQLException e) {
if (e.getMessage().contains("exist")) {
return false;
}
this.plugin.getLogger().info("Error in SQL query: " + e.getMessage());
}
return false;
}
protected static enum Statements
{
SELECT, INSERT, UPDATE, DELETE, DO, REPLACE, LOAD, HANDLER, CALL,
CREATE, ALTER, DROP, TRUNCATE, RENAME;
}
}
Fehler ist switch (1.$SwitchMap$DuB$lv$BungeePortals$Database$Statements[getStatement(query).ordinal()])
Code:
[19:03:20] [Server thread/ERROR]: Error occurred while enabling BungeePortals v1.1 (Is it up to date?)
java.lang.Error: Unresolved compilation problems:
The type of the expression must be an array type but it resolved to double
Syntax error on token "$SwitchMap$DuB$lv$BungeePortals$Database$Statements", delete this token
at DuB.lv.Database.query(Database.java:99) ~[?:?]
at DuB.lv.BungeePortals.onEnable(BungeePortals.java:96) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[spigot.jar:git-Spigot-1360]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [spigot.jar:git-Spigot-1360]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-1360]
at org.bukkit.craftbukkit.v1_7_R2.CraftServer.loadPlugin(CraftServer.java:463) [spigot.jar:git-Spigot-1360]
at org.bukkit.craftbukkit.v1_7_R2.CraftServer.enablePlugins(CraftServer.java:381) [spigot.jar:git-Spigot-1360]
at org.bukkit.craftbukkit.v1_7_R2.CraftServer.reload(CraftServer.java:799) [spigot.jar:git-Spigot-1360]
at org.bukkit.Bukkit.reload(Bukkit.java:279) [spigot.jar:git-Spigot-1360]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:24) [spigot.jar:git-Spigot-1360]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) [spigot.jar:git-Spigot-1360]
at org.bukkit.craftbukkit.v1_7_R2.CraftServer.dispatchCommand(CraftServer.java:709) [spigot.jar:git-Spigot-1360]
at org.bukkit.craftbukkit.v1_7_R2.CraftServer.dispatchServerCommand(CraftServer.java:696) [spigot.jar:git-Spigot-1360]
at net.minecraft.server.v1_7_R2.DedicatedServer.ax(DedicatedServer.java:309) [spigot.jar:git-Spigot-1360]
at net.minecraft.server.v1_7_R2.DedicatedServer.v(DedicatedServer.java:274) [spigot.jar:git-Spigot-1360]
at net.minecraft.server.v1_7_R2.MinecraftServer.u(MinecraftServer.java:566) [spigot.jar:git-Spigot-1360]
at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:472) [spigot.jar:git-Spigot-1360]
at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [spigot.jar:git-Spigot-1360]
Ist aus dem Ban Management
Ich möchte in das Bungeeporals eine Abfrage rein schreiben ob die Leute gebannt sind, kommischerweise ist die switch anweißung falsch und ich kann nicht auf die datenbanken connecten