|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package org.poopki.duckdns.user_db.DB; |
|
|
|
|
|
|
|
|
|
import org.poopki.duckdns.user_db.UserInfo; |
|
|
|
|
import org.poopki.duckdns.user_db.UserInfoArray; |
|
|
|
|
|
|
|
|
|
import java.sql.*; |
|
|
|
@ -19,7 +20,7 @@ public class DBUpdate { |
|
|
|
|
m_InfoArrayInstance = m_UIA; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void UpdateDB(){ |
|
|
|
|
public static void InitDB() throws SQLException { |
|
|
|
|
Connection conn = null; |
|
|
|
|
Statement stmt = null; |
|
|
|
|
|
|
|
|
@ -30,23 +31,18 @@ public class DBUpdate { |
|
|
|
|
System.out.println("Connection success"); |
|
|
|
|
stmt = conn.createStatement(); |
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
/* String sql = sb.append("create table if not exists UserInfo(") |
|
|
|
|
String sql = sb.append("create table if not exists UserInfo(") |
|
|
|
|
.append("UUID varchar(36),") |
|
|
|
|
.append("Nation int(8)") |
|
|
|
|
.append("Occupation TINYINT,") |
|
|
|
|
.append("Squad int,") |
|
|
|
|
.append("Farm int,") |
|
|
|
|
.append("Account int,") |
|
|
|
|
.append("Nation int(8),") //public
|
|
|
|
|
.append("Squad int(8),") //public
|
|
|
|
|
.append("Farm int(8)") //public
|
|
|
|
|
/* |
|
|
|
|
.append("Occupation int(8),") //private
|
|
|
|
|
.append("Account int(8),") //private
|
|
|
|
|
.append("Status int(8)") //private*/
|
|
|
|
|
.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();
|
|
|
|
|
String sql = sb.append("insert into UserInfo values ('test', 0)").toString(); |
|
|
|
|
stmt.execute(sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (ClassNotFoundException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
@ -55,8 +51,86 @@ public class DBUpdate { |
|
|
|
|
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 { |
|
|
|
|
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(); |
|
|
|
|
String sql = "SELECT * FROM UserInfo"; |
|
|
|
|
ResultSet rs = stmt.executeQuery(sql); |
|
|
|
|
|
|
|
|
|
while(rs.next()){ |
|
|
|
|
m_InfoArrayInstance.m_UserInfoArray.put(UUID.fromString(rs.getString(1)), new UserInfo(UUID.fromString(rs.getString(1)), |
|
|
|
|
Integer.parseInt(rs.getString(2)), |
|
|
|
|
Integer.parseInt(rs.getString(3)), |
|
|
|
|
Integer.parseInt(rs.getString(4)))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} 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 void UpdateDB() throws SQLException { |
|
|
|
|
Connection conn = null; |
|
|
|
|
PreparedStatement pstmt = null; |
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
Class.forName("org.mariadb.jdbc.Driver"); |
|
|
|
|
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); |
|
|
|
|
|
|
|
|
|
for (UUID key : m_InfoArrayInstance.m_UserInfoArray.keySet()) { |
|
|
|
|
//sql = sb.append("insert into UserInfo values('"+key+"',"+0+","+0+","+0+","+0+","+0+")").toString();
|
|
|
|
|
//String sql = sb.append("insert into UserInfo values ('test', 0)").toString();
|
|
|
|
|
//stmt.execute(sql);
|
|
|
|
|
String sql = "INSERT INTO UserInfo VALUES (?,?,?,?)"; |
|
|
|
|
pstmt = conn.prepareStatement(sql); |
|
|
|
|
//pstmt.setString(1, key.toString());
|
|
|
|
|
pstmt.setString(1, String.valueOf(m_InfoArrayInstance.m_UserInfoArray.get(key).getUserUUID())); |
|
|
|
|
pstmt.setString(2, String.valueOf(11)); |
|
|
|
|
pstmt.setString(3, String.valueOf(12)); |
|
|
|
|
pstmt.setString(4, String.valueOf(33)); |
|
|
|
|
|
|
|
|
|
int cnt = pstmt.executeUpdate(); |
|
|
|
|
if( cnt == 0 ){ |
|
|
|
|
System.out.println("데이터 입력 실패"); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
System.out.println("데이터 입력 성공"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch(ClassNotFoundException e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
catch(SQLException e){ |
|
|
|
|
System.err.println("에러 내용 :" + e.getMessage()); |
|
|
|
|
System.out.println("DB Connection fail"); |
|
|
|
|
} |
|
|
|
|
finally { |
|
|
|
|
if( conn != null && !conn.isClosed()){ |
|
|
|
|
conn.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |