package noppes.npcs.client.gui.util;
import java.sql.*;
import java.util.Objects;
public class MySQL {
private static String address;
private static String username;
private static String password;
private static Connection link;
private static ResultSet result;
public static Statement stmt;
static {
MySQL.address = "jdbc:mysql://localhost/testbd";
MySQL.username = "test";
MySQL.password = "123qwe";
}
public static boolean Contains(String query, String column, String trueResponse) {
try {
MySQL.link = DriverManager.getConnection(MySQL.address, MySQL.username, MySQL.password);
MySQL.stmt = MySQL.link.createStatement();
MySQL.result = MySQL.stmt.executeQuery(query);
if (MySQL.result.next()) {
if (MySQL.result.wasNull()) {
return false;
}
return Objects.equals(MySQL.result.getString(column), trueResponse);
}
}
catch (SQLException e) {
throw new RuntimeException(e);
}
return false;
}
public static String getString(String query, String column) {
try {
MySQL.link = DriverManager.getConnection(MySQL.address, MySQL.username, MySQL.password);
MySQL.stmt = MySQL.link.createStatement();
MySQL.result = MySQL.stmt.executeQuery(query);
if (MySQL.result.next()) {
if (MySQL.result.wasNull()) {
return null;
}
return MySQL.result.getString(column);
}
}
catch (SQLException e) {
throw new RuntimeException(e);
}
return null;
}
public static void sendQuery(String query) {
try {
MySQL.link = DriverManager.getConnection(MySQL.address, MySQL.username, MySQL.password);
MySQL.stmt = MySQL.link.createStatement();
MySQL.stmt.executeUpdate(query);
MySQL.link.close();
}
catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
String query = String.format("SELECT `ammount` FROM `items` WHERE item=\"%s\"", item);
query = String.format("SELECT `ammount` FROM `items` WHERE item=\"%s\"", item);
if (!MySQL.Contains(query, "ammount", null)) {
String ammountt = MySQL.getString(query, "ammount");
fontRendererObj.drawString("*", x + 45, y + 22, 16777215);
return;
} else {
query = String.format("INSERT INTO `items` (`id`, `ammount`, `item`) VALUES (NULL, '10000', '%s'))", item);
MySQL.sendQuery(query);
}