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
+36 -16
View File
@@ -1,25 +1,26 @@
package com.softwarerat.SQL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
public class Homes {
AsyncSQLHandler sqlHandler;
public Homes(AsyncSQLHandler sqlHandler) {
this.sqlHandler = sqlHandler;
}
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;
try {
resultSet = sqlHandler.executeQuery("SELECT * FROM homes WHERE Name = '" + name + "';");
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
resultSet = ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (resultSet != null) {
try {
@@ -34,11 +35,21 @@ public class Homes {
return null;
}
//FIX: creation with new sql handler
public void createNewHome(PlayerHome playerHome){
PreparedStatement ps = null;
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()+"');");
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
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 (SQLException 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) {
ArrayList<PlayerHome> homes = new ArrayList<>();
ResultSet resultSet = null;
PreparedStatement ps = null;
try {
resultSet = sqlHandler.executeQuery("SELECT * FROM homes WHERE uuid = '" + UUID + "';");
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
ps = MySQL.getConnection().prepareStatement("SELECT * FROM homes WHERE uuid = '" + UUID + "';");
} catch (SQLException 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) {
try {