Fixed loadObject for MySQL.

The uniqueKey needs to be enclosed in quotes "" to work.
This commit is contained in:
Tastybento 2018-04-21 11:41:48 -07:00
parent 6ff8c1a3d8
commit 45101901bd

View File

@ -95,7 +95,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
public List<T> loadObjects() {
List<T> list = new ArrayList<>();
StringBuilder sb = new StringBuilder();
sb.append("SELECT `json` FROM `");
sb.append("SELECT `json` FROM `");
sb.append(dataObject.getCanonicalName());
sb.append("`");
try (Statement preparedStatement = connection.createStatement()) {
@ -115,11 +115,12 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
@Override
public T loadObject(String uniqueId) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT `json` FROM `");
sb.append("SELECT `json` FROM `");
sb.append(dataObject.getCanonicalName());
sb.append("` WHERE uniqueId = ? LIMIT 1");
try (PreparedStatement preparedStatement = connection.prepareStatement(sb.toString())) {
preparedStatement.setString(1, uniqueId);
// UniqueId needs to be placed in quotes
preparedStatement.setString(1, "\"" + uniqueId + "\"");
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
// If there is a result, we only want/need the first one