Fix SQL Bug

DB
poopki 3 years ago
parent 81916c480c
commit e9298f7be0
  1. 61
      DB/DBUpdate.java
  2. 2
      UserInfoArray.java
  3. 10
      UserJoin.java
  4. 7
      User_DB.java

@ -0,0 +1,61 @@
package org.poopki.duckdns.user_db.DB;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class DBUpdate {
private static final String DB_DRIVER_CLASS = "org.mariadb.jdbc.Driver";
private static final String DB_URL = "jdbc:mariadb://poopki.duckdns.org:3307/mc_dev";
private static final String DB_USERNAME = "mc_dev";
private static final String DB_PASSWORD = "!Rkdalsrn1027";
private static UserInfoArray m_InfoArrayInstance;
public DBUpdate(UserInfoArray m_UIA){
m_InfoArrayInstance = m_UIA;
}
public static void UpdateDB(){
Connection conn = null;
Statement stmt = null;
try {
Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
System.out.println("Connection success");
stmt = conn.createStatement();
StringBuilder sb = new StringBuilder();
String sql = sb.append("create table if not exists UserInfo(")
.append("UUID varchar(36)")
/* .append("Nation int,")
.append("Occupation TINYINT,")
.append("Squad int,")
.append("Farm int,")
.append("Account int,")*/
.append(")").toString();
stmt.execute(sql);
for (UUID key : m_InfoArrayInstance.m_UserInfoArray.keySet()) {
//sql = sb.append("insert into UserInfo values('"+key+"',"+0+","+0+","+0+","+0+","+0+")").toString();
sql = sb.append("insert into UserInfo (UUID) value ('"+key.toString()+ "')").toString();
stmt.execute(sql);
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
// TODO Auto-generated catch block
System.err.println("에러 내용 :" + e.getMessage());
System.out.println("DB Connection fail");
}
}
}

@ -7,7 +7,7 @@ import java.util.Map;
import java.util.UUID;
public class UserInfoArray {
static Map<UUID, UserInfo> m_UserInfoArray = new HashMap<UUID, UserInfo>();
public static Map<UUID, UserInfo> m_UserInfoArray = new HashMap<UUID, UserInfo>();
public void getUserInfo(Player p) {
UserInfo m_UserInfo = m_UserInfoArray.get(p.getUniqueId());

@ -5,18 +5,18 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class UserJoin implements Listener {
private UserInfoArray m_InfoArray;
private UserInfoArray m_InfoArrayInstance;
UserJoin(UserInfoArray m_UIA){
m_InfoArray = m_UIA;
m_InfoArrayInstance = m_UIA;
}
@EventHandler
public void PlayerLogin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if(m_InfoArray.m_UserInfoArray.containsKey(p.getUniqueId())){
m_InfoArray.getUserInfo(p);
if(m_InfoArrayInstance.m_UserInfoArray.containsKey(p.getUniqueId())){
m_InfoArrayInstance.getUserInfo(p);
}
else{
m_InfoArray.putUserInfo(p);
m_InfoArrayInstance.putUserInfo(p);
}
}
}

@ -8,17 +8,18 @@ import java.sql.Statement;
public final class User_DB extends JavaPlugin implements Listener {
UserInfoArray m_UIA = new UserInfoArray();
UserInfoArray m_InfoArrayInstance = new UserInfoArray();
@Override
public void onEnable() {
// Plugin startup logic
Connection conn = new DBConnect().connectDB();
getServer().getPluginManager().registerEvents(new UserJoin(m_UIA),this);
getServer().getPluginManager().registerEvents(new UserJoin(m_InfoArrayInstance),this);
}
@Override
public void onDisable() {
// Plugin shutdown logic
DBUpdate Database_backup = new DBUpdate(m_InfoArrayInstance);
Database_backup.UpdateDB();
}
}

Loading…
Cancel
Save