我遇到了一個奇怪的情況。代碼如下:Java奇怪的變量賦值查詢
public static int add(String trcd, String tlcd, String dept, String doDate,
String doTime, String andConfirm, Teller admin) throws
Exception {
try {
String table1 = "table1";
String table2 = "table2";
String trap = null;
String trtype = null;
String sql = "select * from " + table2;
DataSet dataset = DBOper.DBQuery("taUtil", sql);
if (dataset.isEmpty()) {
return -1;
}
else {
HashMap map = dataset.getRow(0);
trap = (String) map.get("aut_ap_code");
trtype = (String) map.get("aut_type_code");
//point 1
sql = "insert into " + table1 + " values("+trtype + "','" + doDate + "','" + doTime + "','N','Y')";
DBOper.DBUpdate("taUtil", sql);
if (andConfirm.equals("Y")) {
//point 2
sql = "select * " + table1 +" where tr_create_date='" + doDate + "' and tr_create_time='" + doTime + "' and tr_stcd='Y'";
//point 3
DataSet dataset2 = DBOper.DBQuery("taUtil", sql);
if (dataset2.isEmpty()) {
return -2;
}
else {
String trNo = null;
HashMap map2 = dataset2.getRow(0);
trNo = (String) map2.get("tr_no");
confirm(admin, trNo, "N");
}
}
return 0;
}
}
catch (Exception e) {
throw e;
}
}
的問題是:
第3點,它 始終打印「插入」,即以前的SQL值,而不是最新分配「選擇」。
有誰知道爲什麼會這樣? 感謝
重現該問題的郵政編碼和每個人都可以編譯它擁有JDK –
不想稱你爲騙子,但很難相信。你能重新編譯這段代碼,並確保你正在運行你在這裏發佈的內容嗎? –
在'sql =「插入到」+ ...'行,以''values ...'開頭的字符串沒有未轉義的引號。代碼如何編譯? – nhahtdh