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
编辑你的问题并显示表结构你打算使用。 –