package org.poopki.duckdns.user_db.DB; import org.poopki.duckdns.user_db.*; import org.poopki.duckdns.user_db.Array.AccountArray; import org.poopki.duckdns.user_db.Array.FarmArray; import org.poopki.duckdns.user_db.Array.NationArray; import java.sql.*; import java.util.ArrayList; import java.util.List; 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; private static AccountArray m_AccountArray; private static FarmArray m_FarmArray; private static NationArray m_NationArray; UUID ZERO_UUID = new UUID(0,0); static int MAX_FARM_NUM = 13; public DBUpdate(UserInfoArray UIA, AccountArray AA, FarmArray FA, NationArray NA){ m_InfoArrayInstance = UIA; m_AccountArray = AA; m_FarmArray = FA; m_NationArray = NA; } public static void InitDB() throws SQLException { // 플러그인 초기 사용 시 테이블 생성 Connection conn = null; Statement stmt; 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) PRIMARY KEY,") .append("Name varchar(15), ") .append("Nation varchar(36),") //public .append("Squad varchar(36),") //public .append("Farm varchar(36),") //public .append("Account int(10)") //public /* .append("Occupation int(8),") //private .append("Account int(8),") //private .append("Status int(8)") //private*/ .append(")").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"); } finally { if( conn != null && !conn.isClosed()){ conn.close(); } } } public static void LoadDB() throws SQLException { //서버 초기 구동 시 DB 로드 Connection conn = null; Statement stmt; try { Class.forName("org.mariadb.jdbc.Driver"); conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); System.out.println("Connection success"); stmt = conn.createStatement(); String sql = "SELECT * FROM UserInfo"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ m_InfoArrayInstance.putUserInfo(UUID.fromString(rs.getString(1)), rs.getString(2), UUID.fromString(rs.getString(3)), UUID.fromString(rs.getString(4)), UUID.fromString(rs.getString(5)), new UUID(0,0)); m_AccountArray.putAccountInfo(UUID.fromString(rs.getString(1)),Integer.parseInt(rs.getString(6))); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block System.err.println("에러 내용 :" + e.getMessage()); System.out.println("DB Connection fail"); }finally{ if(conn != null && !conn.isClosed()){ conn.close(); } } try { Class.forName("org.mariadb.jdbc.Driver"); conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); System.out.println("Connection success"); stmt = conn.createStatement(); String sql = "SELECT * FROM Farm"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ List m_MemberList = new ArrayList<>(); for(int index = 4; index m_MemberList = new ArrayList<>(); for(int index = 4; index