How can I check if a string is available in a table?

mmuncada

Here's the table (tblemployees) How can I convert my code that used text files to a code that will use database (tables).

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.");
    }
}

Now I would like to search a column if it contains an Employee number. How do I put it to a condition, I've been searching but unable to find a clear answer. They only put how to search like this

String queryCheck = "SELECT * from messages WHERE EmpIDNo = 'COMSCI0001'";
ResultSet res = st.executeQuery(queryCheck);

then I'm lost, how to make a condition where if the employee no. doesn't exists something would happen else something would happen. I'm just confuse how to make a condition for that.

janos

You can do like this:

String queryCheck = "SELECT * FROM messages WHERE EmpIDNo = 'COMSCI0001' LIMIT 1";
ResultSet res = st.executeQuery(queryCheck);
boolean exists = res.next();

The boolean variable exists will indicate whether a matching record exists or not.

Notice that I added LIMIT 1 at the end of the SQL as an optimization to avoid fetching more data than you really need.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How I can check if it something available in socket?

From Dev

How can I bypass available memory check?

From Dev

How can I check latest available version of Symfony with any API?

From Dev

How can I check the available shells in Mac OSX?

From Dev

How can I check the available version of a package in the repositories?

From Dev

How can I check which terminal definitions are available?

From Dev

How can I check if cgroups are available on my Linux host?

From Dev

How can I check the last letter of a string?

From Dev

How can I check the position of \"results\":[{ in a string?

From Dev

How can I check the format of string input

From Dev

How can I check if a string is a number in Python?

From Dev

How can I use a where clause and check if a string variable contains in a many table column

From Dev

How can I check that a string does not include the text of another string?

From Dev

How can i check if a string matches String array

From Dev

How can i check string value in String array?

From Dev

How can I check if a certain string is at the start of a string?

From Dev

How can I check if a string is part of another string then replace it

From Dev

how can check if server and port is available in nodejs ?

From Dev

How do I check if a package is available for install?

From Dev

How do I check if a package is available for install?

From Dev

How can I check and change the partition table type?

From Dev

How can i check the radiobutton that it has been checked in this table?

From Dev

How can I check with SQL if variable is exist in table

From Dev

How can I check an other table before updating?

From Dev

How can I read table of type "table of String"?

From Dev

How can I read table of type "table of String"?

From Dev

How can I check if BMI2 instructions are available in my ifunc resolver?

From Dev

Using Firebase Security rules, how can I check for available usernames without making the entire node public?

From Dev

Using Firebase Security rules, how can I check for available usernames without making the entire node public?

Related Related

  1. 1

    How I can check if it something available in socket?

  2. 2

    How can I bypass available memory check?

  3. 3

    How can I check latest available version of Symfony with any API?

  4. 4

    How can I check the available shells in Mac OSX?

  5. 5

    How can I check the available version of a package in the repositories?

  6. 6

    How can I check which terminal definitions are available?

  7. 7

    How can I check if cgroups are available on my Linux host?

  8. 8

    How can I check the last letter of a string?

  9. 9

    How can I check the position of \"results\":[{ in a string?

  10. 10

    How can I check the format of string input

  11. 11

    How can I check if a string is a number in Python?

  12. 12

    How can I use a where clause and check if a string variable contains in a many table column

  13. 13

    How can I check that a string does not include the text of another string?

  14. 14

    How can i check if a string matches String array

  15. 15

    How can i check string value in String array?

  16. 16

    How can I check if a certain string is at the start of a string?

  17. 17

    How can I check if a string is part of another string then replace it

  18. 18

    how can check if server and port is available in nodejs ?

  19. 19

    How do I check if a package is available for install?

  20. 20

    How do I check if a package is available for install?

  21. 21

    How can I check and change the partition table type?

  22. 22

    How can i check the radiobutton that it has been checked in this table?

  23. 23

    How can I check with SQL if variable is exist in table

  24. 24

    How can I check an other table before updating?

  25. 25

    How can I read table of type "table of String"?

  26. 26

    How can I read table of type "table of String"?

  27. 27

    How can I check if BMI2 instructions are available in my ifunc resolver?

  28. 28

    Using Firebase Security rules, how can I check for available usernames without making the entire node public?

  29. 29

    Using Firebase Security rules, how can I check for available usernames without making the entire node public?

HotTag

Archive