Domanda

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!

È stato utile?

Soluzione

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.

Altri suggerimenti

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)
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top