Java(3)
-
SQLiteOpenHelper 를 이용한 SQLite3 제어
# SQLiteOpenHelper 상속 받은 객체 생성 public class WYSQLiteOpenHelper extends SQLiteOpenHelper { public static final int DATABASE_VERSION = 1; public static final String DATABASE_NAME = "wy_database.db3"; private static final String SQL_CREATE = "CREATE TABLE IF NOT EXISTS tb_wy (" + "uid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," + "title TEXT NOT NULL)"; private static final String SQL_DELETE = "DR..
2020.07.23 -
JSON 키 존재, 값 존재 여부 체크
# JSON Object 생성 JSONObject obj = new JSONObject(); try { obj.put("key1", "value1"); obj.put("key2", null); } catch (JSONException e) { e.printStackTrace(); } # 키 존재 여부 체크 if(obj.has("key1")){ System.out.println("key1 has"); }else{ System.out.println("key1 not has"); } if(obj.has("key2")){ System.out.println("key2 has"); }else{ System.out.println("key2 not has"); } if(obj.has("key3")){ System.ou..
2020.07.22 -
HashMap 전체 참조(foreach) 방법 (Java)
HashMap 에 포함된 Key, Value 값을 모두 확인하는 방법 # 데이터 생성 HashMap map = new HashMap(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); # 방법 1 Iterator keys = map.keySet().iterator(); while( keys.hasNext() ){ String strKey = keys.next(); String strValue = map.get(strKey); System.out.println( strKey +":"+ strValue ); } # 방법 2 for( Map.Entry entry : map.entrySet() ){ String s..
2020.07.21