Here's the table (tblemployees) 如何將我使用文本文件的代碼轉換爲將使用數據庫(表)的代碼。如何檢查表格中是否有字符串?
int intcurrentLine = -1;
String[] strLineSplit = (sb.toString()).split("\\r?\\n"); // converts sb to string then splits it by line
int intNumElements = strLineSplit.length; // number of elements
while (intcurrentLine != (intNumElements - 1)) {
intcurrentLine++;
String[] strWords = (strLineSplit[intcurrentLine]).split(" ", 2); // splits the current line by the first instance(space)
if (strEmpID.equals(strWords[0])) { // checks if the employee ID is available
JOptionPane.showMessageDialog(null, "Welcome " + strWords[1] + ", you have successfully logged in.");
strCheck = 1; // to confirm and go to time in and out process
break;
}
if ((intcurrentLine + 1) == intNumElements) { // condition to state that ID cant be found from the employee list
JOptionPane.showMessageDialog(null, "No such employee, please check the ID No. that you entered.");
}
}
現在我想搜索一個列,如果它包含一個僱員號碼。我如何把它放到一個條件,我一直在尋找,但無法找到明確的答案。他們只是把如何搜索這樣的
String queryCheck = "SELECT * from messages WHERE EmpIDNo = 'COMSCI0001'";
ResultSet res = st.executeQuery(queryCheck);
然後我迷路了,如何做一個條件,如果僱員沒有。不存在的事情會發生其他事情會發生。我只是混淆瞭如何爲此做出一個條件。
一種方法是檢查結果有多少條記錄。另一個將直接計數在查詢中,並檢查計數:'SELECT count(*)as emp_cnt from messages WHERE EmpIDNo ='COMSCI0001'' –
use'res.next()'method – Rehman
編輯你的問題並顯示錶結構你打算使用。 –