Skip to content

Commit

Permalink
Merge branch 'master' into dev-v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Almighty-Satan committed Aug 23, 2024
2 parents 67a51cf + 0a3b1d6 commit 76423c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/de/cuuky/varo/bot/discord/register/BotRegister.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.cuuky.varo.bot.discord.register;

import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -245,8 +246,18 @@ public static void saveAll() {

Main.getDataManager().getMysqlClient().update("TRUNCATE TABLE " + TABLE + ";");

for (final BotRegister reg : register) {
Main.getDataManager().getMysqlClient().update("INSERT INTO " + TABLE + " (uuid, userid, code, bypass, name) VALUES ('" + reg.getUUID() + "', " + (reg.getUserId() != -1 ? reg.getUserId() : "null") + ", " + reg.getCode() + ", " + reg.isBypass() + ", '" + (reg.getPlayerName() == null ? "null" : reg.getPlayerName()) + "');");
try (PreparedStatement preparedStatement = Main.getDataManager().getMysqlClient().prepareStatement("INSERT INTO " + TABLE + " (uuid, userid, code, bypass, name) VALUES (?, ?, ?, ?, ?)")) {
for (final BotRegister reg : register) {
preparedStatement.setString(1, reg.getUUID());
preparedStatement.setLong(2, reg.getUserId() != -1 ? reg.getUserId() : null);
preparedStatement.setInt(3, reg.getCode());
preparedStatement.setBoolean(4, reg.isBypass());
preparedStatement.setString(5, reg.getPlayerName());
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
}
} else {
File file = new File("plugins/Varo", "registrations.yml");
Expand Down
12 changes: 12 additions & 0 deletions src/de/cuuky/varo/mysql/MySQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -79,6 +80,17 @@ public void update(String qry) {
connect();
}
}

public PreparedStatement prepareStatement(String query) throws SQLException {
try {
return connection.prepareStatement(query);
} catch (SQLException e) {
e.printStackTrace();
System.err.println(Main.getConsolePrefix() + "Connection to MySQL-Database lost!");
connect();
return connection.prepareStatement(query);
}
}

public boolean isConnected() {
return connected;
Expand Down

0 comments on commit 76423c0

Please sign in to comment.