mercredi 17 novembre 2021

I am trying to get data from a row in a table items in which a column is 'itemName' in itemName there a 10 values

now user come to my program and enter the name of any value,then i want to show the value.

System.out.println("enter name of item you want to order");
String userOrder = br.readLine();

Connection con = ConnectionToDB.connection();
String itemName= "select itemName from items";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(itemName);

while(rs.next())
{
    if (rs.getString("itemName").equals(userOrder))
    {
        System.out.println(rs.getString("itemName"));
    }
    else
    {
        System.out.println("you order wrong item that not present");
    }
}

when user enter 1st value that present in table that execute well and show the first values but when user input any other value that present in database but rs.next() is not working and else part executed. How can I overcome this?

Aucun commentaire:

Enregistrer un commentaire