Frage

I'm not sure how to write it in a way the query will take all the values stored in the excludeRooms and use it in the query then add the results to the tableRoomsData vector

Code:

    List<String> excludeRooms = new ArrayList<String>();
    Vector<String> tableRoomsData = new Vector<String>();

    m.dbConnect(); 

    PreparedStatement stmt = m.getCon().prepareStatement("SELECT * FROM room_view
                WHERE room_num != ?");
    //get all data where room_num is not equal to the room numbers stored in excludeRooms


    result = stmt.executeQuery();

    while (result.next()) {
    d.add(result.getString("room_num");
    d.add(result.getString("room_type");
    }

PS. I'm a total newbie in Java and is trying to create a program alongside learning on my own. This is also my first time to post a question here so I hope you could bear with me on my formatting. Thank y'all in advance!

War es hilfreich?

Lösung

You have to use WHERE NOT IN clause to get this done.

So your query should look like, SELECT * FROM room_view WHERE room_num NOT IN ("r1", "r2", "r3"); Where the r1, r2, r3 are the room numbers stored in your excludeRooms;

On Java part you can write a loop to put these values to the stmt;

Let me know if it is not clear.

Andere Tipps

Firstly - set the ps.setString(1, roomNumber) as argument

Secondly - In the While Loop - initiate the VO (Value Object) and then add it as list.

Just return the excludeRooms list.

Try this

while (result.next()) {
VOObject vo=new VOObject();
    VOObject.setRootNum(result.getString("room_num");
    VOObject.setRootType(result.getString("room_type");
excludeRooms.add(VOObject)
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top