1

For a school exercise I need to get some information from a database.

We need to scan a RFID card and lookup in the database. But when I try to print out the line in the IDE I get more results than I want.

The RFID tag something like: 2R KL MZ 89 and if I try to get it from the database I get: Access Granted. (because that is the record that is right) and Access Denied. (because that is the record which is wrong.

Long story short: How do I get ONLY Access Granted. when the tag is correct and ONLY Access Denied.

Code:

while (rs.next()) {

        String number = rs.getString("number");

        if (number.equals(key)) {
            System.out.println("Access Granted.");
        } else {
            System.out.println("Access Denied");
        }
    }

Table:

My table is only id, which is auto increment, and the other row is called number which contains two records: the right tag and the wrong one.

4

1 回答 1

1

您应该使用如下查询:

从 myTable 中选择 1,其中 RF_ID = key

使用这个,如果密钥存在,您将有一条线,否则没有线。

如果您只需要查找表中的特定值,那么循环多行是没有用的。

于 2012-12-05T14:11:48.167 回答