made sql working again
This commit is contained in:
Binary file not shown.
@@ -23,23 +23,12 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.28</version>
|
||||
<scope>compile</scope>
|
||||
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.mint</groupId>
|
||||
<artifactId>AsyncMySQLPoolHandler</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitlab-zyonic</id>
|
||||
<url>https://gitlab.zyonicsoftware.com/api/v4/projects/119/packages/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.softwarerat;
|
||||
|
||||
import com.softwarerat.SQL.AsyncSQLHandler;
|
||||
|
||||
import com.softwarerat.SQL.Homes;
|
||||
import com.softwarerat.SQL.MySQL;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class Main {
|
||||
AsyncSQLHandler asyncSQLHandler;
|
||||
|
||||
Homes homes;
|
||||
public void enableAPI(String user, String pw, String Database, String host){
|
||||
asyncSQLHandler = new AsyncSQLHandler(host,user,pw,Database);
|
||||
homes = new Homes(asyncSQLHandler);
|
||||
MySQL.connect();
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user