首先利用下面的 SQL Command,即可將刪除 Table 之 SQL command 全部產生出來:
select 'drop table '||table_name||' cascade constraints;' from user_tables order by table_name
接下來批次執行所有產生出來的 SQL command 即可
2015年1月21日 星期三
2015年1月18日 星期日
JSON 與 Map 互轉 (使用 GSON)
import java.lang.reflect.Type;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
public class JsonUtils {
public static Map<String, Object> fromJson(String json) {
return fromJson(json, Map.class);
}
public static String toJson(Object src) {
Gson gson = new Gson();
return gson.toJson(src);
}
public static <T> T fromJson(String json, Type typeOfT) {
Gson gson = new Gson();
return (T) gson.fromJson(json, typeOfT);
}
public static boolean isValidJson(String json) {
try {
fromJson(json);
return true;
} catch(JsonSyntaxException ex) {
return false;
}
}
public static boolean isValidJson(String json, Type typeOfT) {
try {
fromJson(json, Map.class);
return true;
} catch(JsonSyntaxException ex) {
return false;
}
}
}
使用方式:
[JSON 轉 Map]
Map<String,
Object> retMap = JsonUtils.fromJson(jsonData);
傳入 JSON 字串 jsonData
==> JsonUtils.fromJson(jsonData)
回傳型態為 Map<String, Object> 之 map: retMap
[Map 轉 JSON]
String
jsonString = JsonUtils.toJson(mapData);
傳入 型態為
Map<String, Object> 之 map mapData ==> JsonUtils.toJson(mapData);
回傳 JSON 字串 jsonString
2014年12月8日 星期一
將 Set 依指定分割符號轉回字串
//將 Set<String>
依指定分割符號轉回字串
public static String stringSetToStringWithSplitChar(Set<String>
stringSet, String splitChar) throws Exception {
String returnString = "";
for (String key :
stringSet) {
if (returnString.length() > 0)
returnString = returnString + splitChar + key;
else {
returnString = key;
}
}
return returnString;
}
字串依分割符號轉為 Set
//將字串依分割符號轉成 Set<String>
public static Set<String> splitToStringSet(String sourceString,
String splitChar) throws Exception {
Set<String> stringSet = new HashSet<String>();
String[] stringAry = sourceString.split(splitChar);
for (int i = 0; i <
stringAry.length; i++) {
stringSet.add(stringAry[i]);
}
return stringSet;
}
字串陣列轉 Set
//String 陣列 --> Set<String>
public static Set<String> stringArrayToSet(String[] inputArray) throws Exception {
Set<String> returnSet = new HashSet<String>();
for (int i = 0; i <
inputArray.length; i++) {
returnSet.add(inputArray[i]);
}
return returnSet;
}
訂閱:
文章 (Atom)