Skip to content

Commit

Permalink
create statement fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Netherwhal committed Mar 10, 2024
1 parent eafc937 commit 5b10f43
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/main/java/net/simplyvanilla/simplynicks/database/TeamMySQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,32 @@ public synchronized void connect() {
this.plugin.getConfig().getString("database.username"),
this.plugin.getConfig().getString("database.password"));

PreparedStatement teamTableCheckQuery = this.connection.prepareStatement(
this.statement = this.connection.createStatement();

String teamTableCheckQuery = String.format(
"""
CREATE TABLE IF NOT EXISTS ? (
CREATE TABLE IF NOT EXISTS `%s` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` varchar(256) NOT NULL,
`color` varchar(256) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `name` (`name`)
);
"""
""", this.teamTableName
);
teamTableCheckQuery.setString(1, this.teamTableName);
teamTableCheckQuery.executeUpdate();
this.statement.executeUpdate(teamTableCheckQuery);

PreparedStatement playerTeamTableCheckQuery = this.connection.prepareStatement(
String playerTeamTableCheckQuery = String.format(
"""
CREATE TABLE IF NOT EXISTS ? (
CREATE TABLE IF NOT EXISTS `%s` (
`id` BINARY(16) NOT NULL,
`team_id` INT NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`team_id`) REFERENCES ?(`id`) ON DELETE CASCADE
FOREIGN KEY (`team_id`) REFERENCES `%s`(`id`) ON DELETE CASCADE
);
"""
""", this.playerTeamTableName, this.teamTableName
);
playerTeamTableCheckQuery.setString(1, this.playerTeamTableName);
playerTeamTableCheckQuery.setString(2, this.teamTableName);
playerTeamTableCheckQuery.executeUpdate();
this.statement.executeUpdate(playerTeamTableCheckQuery);

this.plugin.getLogger().log(Level.INFO, "Connected to the MySQL server!");
} catch (Exception ex) {
Expand Down

0 comments on commit 5b10f43

Please sign in to comment.