I want to write a query where i can (but dont have to) specify certain things. I am writing a booking app for a school project, and our first scenario is programming a search function. So i have created a GUI for the app, it has 4 text fields - one where you write the name of the hotel, one where you write the maximum price for the trip(stay), one where you write the date start and the last one where you write the date end. Then there are 3 checkboxes, one for the country in which the hotel should be, second for the number of start the hotel should have and the last one for the number of people. So far i have have success with this query which only uses the first textfield for hotel name:
String query = "SELECT h.\"Nazov hotela\", k.\"Nazov krajiny\", m.\"Nazov mesta\", h.\"Adresa hotela\", h.\"Hviezdicky\", p.\"Cena\", i.\"Typ izby\", h.\"Pocet izieb\" FROM hotel h
LEFT JOIN izba i ON i.\"ID hotela\" = h.\"ID hotela\"
LEFT JOIN krajina k ON k.\"ID krajiny\" = h.\"ID krajiny\"
LEFT JOIN mesto m ON m.\"ID mesta\" = h.\"ID mesta\"
LEFT JOIN pobyt p ON p.\"ID hotela\" = h.\"ID hotela\"
WHERE h.\"Nazov hotela\" = ?"
and the code for inputing the query is
PreparedStatement pst = con.prepareStatement(query);
pst.setString(1,text_pole_result.getText());
//System.out.println(pst);
ResultSet rs = pst.executeQuery();
So i am unsure how to introduce 6 more where=? statements into the query. Here is an image of the GUI: https://gyazo.com/eb2665c337f4719b6485535f9f61c8ff
Aucun commentaire:
Enregistrer un commentaire