Hello all.
I have never updated a single column in a specific record.
I am using Apache derby embedded database.
I have used the update prepared statement to up date a single field with the String value but it updates all the like of every record.
How can I update a specific record’s with an int bookNum to update its status field String value? I have 2 unknown values to handle.

Statement:

<entry key="insertNewStatus">UPDATE booking SET book_status =? WHERE book_num=?</entry>

DAO: I tried this code but I just want to see how to introduce the two unknown “?” properly.
I am rewriting a few classes at the moment so I can not run it at the moment but this code compiles.
Thanks

public boolean insertNewStatus(int aBookNum,String aStatus) throws UnknownUserNameException, InterruptedException {

        boolean bInserted = true;

        int bookNum=aBookNum;
        String status=aStatus;

        setTableName(tableName);


        conn = connect();
        ps = (PreparedStatement) conn.prepareStatement(
                ModelUtils.getXMLResource("insertNewStatus"));
        ps.setString(1, status);
         ps.setInt(2, bookNum);

        ps.executeUpdate();
        /*
         *  int rowCount = ps.executeUpdate();
        if (rowCount != 1) {
        bInserted = false;
        
        }
         */

        return bInserted;
    }

Is there some code I could add here to check to see if the field was successfully updated?

are there duplicate entries for field book_num in the table booking ?

are there duplicate entries for field book_num in the table booking ?

Thanks. that is a really good question. But,No book_num is PK. In my code I put the contents in my post in the program and had not had a chance to run it because of a major re-write but when I did I found that I was not even using book_num. I a had the wrong var in there by mistake. I finally found that.
problem. I did not know you could have two unknowns (?) in a statement but it works the
same if you set them all in order.
Thank you for your time.

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.