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;
          	}



       }
Member Avatar for ztini

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))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.