|
@@ -1,9 +1,41 @@
|
|
|
package xyz.prismix.OPCAI_server.DataBase;
|
|
|
|
|
|
+import jakarta.annotation.Nullable;
|
|
|
import xyz.prismix.OPCAI_server.DataBase.Objects.Card;
|
|
|
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
+
|
|
|
public class SQLCardDatabase {
|
|
|
- public static void addCard(Card card) {
|
|
|
+ static Connection connection = SQLUserDatabase.connection;
|
|
|
+ public static void addCard(Card card) throws SQLException {
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ statement.execute(STR."""
|
|
|
+ INSERT INTO OPCAI.Cards
|
|
|
+ VALUES (\{card.getId()}, \{card.getName()}, \{card.getAtk1()}, \{card.getAtk1dmg()}, \{card.getAtk2()}, \{card.getAtk2()})
|
|
|
+ """);
|
|
|
+ }
|
|
|
|
|
|
+ @Nullable
|
|
|
+ public static Card getCard(int id) throws SQLException {
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ ResultSet set = statement.executeQuery(STR."""
|
|
|
+ SELECT * FROM OPCAI.Cards
|
|
|
+ WHERE id=\{id}
|
|
|
+ """);
|
|
|
+ if (set.next()) {
|
|
|
+ Card card = new Card(
|
|
|
+ set.getInt(1),
|
|
|
+ set.getString(2),
|
|
|
+ set.getString(3),
|
|
|
+ set.getInt(4),
|
|
|
+ set.getString(5),
|
|
|
+ set.getInt(6)
|
|
|
+ );
|
|
|
+ return card;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|