SQL Fixes

:)
This commit is contained in:
Paldiu 2021-03-19 10:39:58 -05:00
parent 2a87271642
commit b03870c0aa
2 changed files with 9 additions and 9 deletions

View File

@ -1,11 +1,7 @@
package me.totalfreedom.totalfreedommod.bridge;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Collections;
@ -228,11 +224,12 @@ public class CoreProtectBridge extends FreedomService
String database = ConfigEntry.COREPROTECT_MYSQL_DATABASE.getString();
String url = host + ":" + port + "/" + database + "?user=" + username + "&password=" + password + "&useSSL=false";
connection = DriverManager.getConnection("jdbc:sql://" + url);
final Statement statement = connection.createStatement();
final PreparedStatement statement = connection.prepareStatement("SELECT id FROM co_world WHERE world = ?");
statement.setQueryTimeout(30);
// Obtain world ID from CoreProtect database
ResultSet resultSet = statement.executeQuery("SELECT id FROM co_world WHERE world = '" + world.getName() + "'");
statement.setString(1, world.getName());
ResultSet resultSet = statement.executeQuery();
String worldID = null;
while (resultSet.next())
{
@ -250,7 +247,10 @@ public class CoreProtectBridge extends FreedomService
// Iterate through each table and delete their data if the world ID matches
for (String table : tables)
{
statement.executeQuery("DELETE FROM " + table + " WHERE wid = " + worldID);
final PreparedStatement statement1 = connection.prepareStatement("DELETE FROM ? WHERE wid = ?");
statement1.setString(1, table);
statement1.setString(2, worldID);
statement1.executeQuery();
}
connection.close();

View File

@ -139,7 +139,7 @@ public class WorldRestrictions extends FreedomService
event.setCancelled(true);
}
if (command.equals("coreprotect") || command.equals("core") || command.equals("co"))
if (command.equalsIgnoreCase("coreprotect") || command.equalsIgnoreCase("core") || command.equalsIgnoreCase("co"))
{
player.sendMessage(ChatColor.RED + "Only " + allowed + " are allowed to use CoreProtect here.");
event.setCancelled(true);