made sql working again

This commit is contained in:
Laura
2026-01-18 16:13:27 +01:00
parent f1c858bf5f
commit 4f192337fc
6 changed files with 88 additions and 74 deletions
Binary file not shown.
+7 -18
View File
@@ -23,23 +23,12 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.28</version> <version>1.18.42</version>
<scope>compile</scope> <scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>de.mint</groupId>
<artifactId>AsyncMySQLPoolHandler</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies> </dependencies>
<repositories>
<repository>
<id>gitlab-zyonic</id>
<url>https://gitlab.zyonicsoftware.com/api/v4/projects/119/packages/maven</url>
</repository>
</repositories>
</project> </project>
+6 -4
View File
@@ -1,16 +1,18 @@
package com.softwarerat; package com.softwarerat;
import com.softwarerat.SQL.AsyncSQLHandler;
import com.softwarerat.SQL.Homes; import com.softwarerat.SQL.Homes;
import com.softwarerat.SQL.MySQL;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
public class Main { public class Main {
AsyncSQLHandler asyncSQLHandler;
Homes homes; Homes homes;
public void enableAPI(String user, String pw, String Database, String host){ public void enableAPI(String user, String pw, String Database, String host){
asyncSQLHandler = new AsyncSQLHandler(host,user,pw,Database); MySQL.connect();
homes = new Homes(asyncSQLHandler); homes = new Homes();
} }
} }
@@ -1,36 +0,0 @@
package com.softwarerat.SQL;
import java.sql.ResultSet;
import de.mint.asyncmysqlpoolhandler.configservice.ConfigBuilder;
import de.mint.asyncmysqlpoolhandler.configservice.ConfigPoolFramework;
import de.mint.asyncmysqlpoolhandler.enumservice.EnumPoolFramework;
import de.mint.asyncmysqlpoolhandler.mainservice.AsyncMySQLPoolHandler;
import java.sql.ResultSet;
import java.util.concurrent.ExecutionException;
public class AsyncSQLHandler {
private final AsyncMySQLPoolHandler MySQLPoolHandler;
private final ConfigPoolFramework configPoolFramework = ConfigBuilder.getConfigBuilder().build();
public AsyncSQLHandler(String hostname, String user, String pw, String DB) {
this.MySQLPoolHandler = new AsyncMySQLPoolHandler(hostname, user, pw, DB, EnumPoolFramework.HIKARICP, configPoolFramework);
this.openConnection();
}
private void openConnection() {
this.MySQLPoolHandler.openPool();
}
// Basic SQL Things
protected ResultSet executeQuery(String sql) throws ExecutionException, InterruptedException {
return this.MySQLPoolHandler.executeQueryAsync(sql).get();
}
protected void executeUpdate(String sql) throws ExecutionException, InterruptedException {
this.MySQLPoolHandler.executeUpdateAsync(sql).get();
}
}
+36 -16
View File
@@ -1,25 +1,26 @@
package com.softwarerat.SQL; package com.softwarerat.SQL;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
public class Homes { public class Homes {
AsyncSQLHandler sqlHandler;
public Homes(AsyncSQLHandler sqlHandler) {
this.sqlHandler = sqlHandler;
}
public PlayerHome getHomeByName(String name){ public PlayerHome getHomeByName(String name){
PreparedStatement ps = null;
try {
ps = MySQL.getConnection().prepareStatement("SELECT * FROM homes WHERE Name = '" + name + "';");
} catch (SQLException ex) {
System.getLogger(Homes.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
}
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
resultSet = sqlHandler.executeQuery("SELECT * FROM homes WHERE Name = '" + name + "';"); resultSet = ps.executeQuery();
} catch (ExecutionException | InterruptedException e) { } catch (SQLException e) {
throw new RuntimeException(e); // TODO Auto-generated catch block
e.printStackTrace();
} }
if (resultSet != null) { if (resultSet != null) {
try { try {
@@ -34,11 +35,21 @@ public class Homes {
return null; return null;
} }
//FIX: creation with new sql handler
public void createNewHome(PlayerHome playerHome){ public void createNewHome(PlayerHome playerHome){
PreparedStatement ps = null;
try { try {
sqlHandler.executeUpdate("INSERT INTO homes (Name, UUID, World, x, y, z) VALUES ('"+playerHome.getName()+"','"+playerHome.getUUID()+"','"+playerHome.getWorld()+"','"+playerHome.getX()+"','"+playerHome.getY()+"','"+playerHome.getZ()+"');"); ps = MySQL.getConnection().prepareStatement("INSERT INTO homes (Name, UUID, World, x, y, z) VALUES ('"+playerHome.getName()+"','"+playerHome.getUUID()+"','"+playerHome.getWorld()+"','"+playerHome.getX()+"','"+playerHome.getY()+"','"+playerHome.getZ()+"');");
} catch (ExecutionException | InterruptedException e) { } catch (SQLException e) {
throw new RuntimeException(e); // TODO Auto-generated catch block
e.printStackTrace();
}
try {
ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
} }
@@ -46,10 +57,19 @@ public class Homes {
public ArrayList<PlayerHome> getPlayerHomes(String UUID) { public ArrayList<PlayerHome> getPlayerHomes(String UUID) {
ArrayList<PlayerHome> homes = new ArrayList<>(); ArrayList<PlayerHome> homes = new ArrayList<>();
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement ps = null;
try { try {
resultSet = sqlHandler.executeQuery("SELECT * FROM homes WHERE uuid = '" + UUID + "';"); ps = MySQL.getConnection().prepareStatement("SELECT * FROM homes WHERE uuid = '" + UUID + "';");
} catch (ExecutionException | InterruptedException e) { } catch (SQLException e) {
throw new RuntimeException(e); // TODO Auto-generated catch block
e.printStackTrace();
}
try {
resultSet = ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
if (resultSet != null) { if (resultSet != null) {
try { try {
@@ -0,0 +1,39 @@
package com.softwarerat.SQL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MySQL {
private static Connection con;
private static String Host;
private static int port;
private static String database;
private static String user;
private static String password;
public MySQL(String Host, int port, String database, String user, String password) {
MySQL.Host = Host;
MySQL.port = port;
MySQL.database = database;
MySQL.user = user;
MySQL.password = password;
connect();
}
public static void connect() {
try {
con = DriverManager.getConnection("jdbc:mysql://45.85.219.106:3306/Bansystem?autoRecconnect=true", "craftunity", "zFtf5zFTS*ncJrXT");
} catch (SQLException var1) {
System.out.println("SQL Disconected");
System.out.println("SQL Error");
}
}
public static Connection getConnection() {
return con;
}
}