Completely untested, but should point you in the right general direction...
// Connect to database.
Connection C = DriverManager.getConnection("jdbc:mysql://host/database_name","username","password");
// Prepare SQL statement to select details of requested book (by book_id?).
PreparedStatement PStmt = C.prepareStatement("SELECT book_id, book_name, book_count FROM books where book_id=?");
// Requested book id...:)
int requestedBookId = 20;
// Set placeholder value for book id.
PStmt.setInt(1, requestedBookId);
// Execute...
ResultSet RS = PStmt.executeQuery();
// Get record...
RS.first();
// Is the current book count greater than 0...
if ( RS.getInt("book_count") > 0 )
{
// Do whatever with the "client" and "rent" databases
// (did you mean "client" and "rent" tables?)
}
// Close all
PStmt.close();
RS.close();
C.close();
Thanks for the ideea!
And one question: you know i have the 3 tables : books,clients,and rent!how can i do that if somebody rents a book than automaticaly the number of the rented book in the book table substracts with one, i mean nr_book = nr_book -1.
Can somebody help me!
thanks to all
Sorry but i couldn't resolv the probleme!
I have to modify only those values of nrBooks which are rented!
I forgott to say that I have a join table,the idbook,and idclient from book and client table are Fk keys int the rent table.
String modif = "UPDATE book,client,rent set nrbook =nrebook-1 where
book.idbook=rent.idbooki and client.idclient=rent.idclient";
but this sintaz changes all the nrbook to nrbook-1!how shall i do this only for the book wich is rented
Thanks again for the help!!!
You haven't supplied the id of the specific book you're trying to update...
UPDATE book,client,rent SET
nrbook = nrebook-1
WHERE book.idbook=rent.idbooki AND
client.idclient=rent.idclient AND
book.idbook=?
... see use of placeholder "?" as posted earlier.
Gotta say I'm not entirely clear on why you need to join to the "client" and "rent" tables to reduce an available count (ie nrebook) in the "book" table which you already know the id of.