0

I want a user to enter the query: "select * from books where price > 24.99 and price >= 25.00" for example, but since the statement doesn't need price >= 25.00, I want to rewrite the query to just "select * from books where price > 24.99" and give the same results. Can someone give me guidance please? My code and output is below.


Current Output:
Please query from the books database:
select * from books where price > 24.99 and price >= 25.00;

isbn: 978-0-87289-9, author: Kenneth Dolbeare, title: American Political Thought, price: 49.99

Thank you for connecting to books database

Expected Output:
Please query from the books database:
select * from books where price > 24.99 and price >= 25.00;

isbn: 978-0-87289-9, author: Kenneth Dolbeare, title: American Political Thought, price: 49.99


select * from books where price > 24.99;


isbn: 978-0-87289-9, author: Kenneth Dolbeare, title: American Political Thought, price: 49.99


Thank you for connecting to books database

String query;
       String temp = "select * from books where price > 24.99;";



       BufferedReader reader;

       reader = new BufferedReader(new InputStreamReader(System.in));

       System.out.println("Please query from the books database: ");

       query = reader.readLine();



       resultSet = statement.executeQuery(query);
          while (resultSet.next())
          	{

         // Diplaying data of tables

         System.out.println("\nisbn: " + resultSet.getString("isbn") + ", author: "
                                                + resultSet.getString("author") + ", title: "
                                                + resultSet.getString("title") + ", price: "
                                                + resultSet.getDouble("price"));
          	}



       if (query == "select * from books where price > 24.99 and price >= 25.00;")
       {
       	System.out.println("\n"+temp);

       	       resultSet = statement.executeQuery(temp);
          while (resultSet.next())
          	{

         // Diplaying data of tables

         System.out.println("\nisbn: " + resultSet.getString("isbn") + ", author: "
                                                + resultSet.getString("author") + ", title: "
                                                + resultSet.getString("title") + ", price: "
                                                + resultSet.getDouble("price"));
            break;
          	}



       }

Edited by NinjaLink: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by ztini
0

Change your if statement at 31 from:

if (query == "select * from books where price > 24.99 and price >= 25.00;")

to

if (query.equals(temp))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.