I made a button that returns the book in the library and it charges the borrower if the book is overdue but it charges nothing if the book is return within the given return date the error says "Invalid operation at current cursor position."
private void btnReturnActionPerformed(java.awt.event.ActionEvent evt) {
String rCustomer = customerName.getText();
String rDate = Date.getText();
String rBook = bookName.getText();
String rStatus = "Available";
if (rCustomer.equals("") || rDate.equals("")
|| rBook.equals("")) {
JOptionPane.showMessageDialog(this, "Please Enter Required Details");
} else {
try {
String returnDateString = Rset2.getString("RETURNDATE");
Date returnDate = new SimpleDateFormat("yyyy-MM-dd").parse(returnDateString);
Date currentDate = new Date();
long balance = ( currentDate.getTime() - returnDate.getTime() )/ (24 * 60 * 60 * 1000);
if (balance < 0){
String updateSQL = "UPDATE ADMIN1.INVENTORY SET STATUS = '" + rStatus + "', DATE = NULL WHERE BOOKNAME = '" + rBook + "'";
state.executeUpdate(updateSQL);
JOptionPane.showMessageDialog(this, "Book Returned Successfully");
LibraryFrame lib = new LibraryFrame();
lib.setVisible(true);
dispose();
}else {
int choice = JOptionPane.showConfirmDialog(this, "Please pay the fee of: "+ balance, "Alert", JOptionPane.OK_CANCEL_OPTION);
if (choice == JOptionPane.OK_OPTION) {
try {
String deleteSQL = "DELETE FROM ADMIN1.BORROWEDBOOK WHERE CustomerName = '" + rCustomer + "' AND BookName = '"+ rBook + "'";
Rset2 = state.executeQuery(deleteSQL);
JOptionPane.showMessageDialog(this, "Payment Successfull");
} catch( SQLException err ){
System.out.println(err.getMessage());
}
}
}
conn.commit();
Rset.close();
Rset2.close();
state.close();
JOptionPane.showMessageDialog(this, "Book Borrowed Successfully");
LibraryFrame lib = new LibraryFrame();
lib.setVisible(true);
dispose();
} catch (SQLException err) {
System.out.println(err.getMessage());
} catch (ParseException ex) {
Logger.getLogger(returnBook.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
You need to tell us which line of your code gave the "Invalid operation at cursor position" error. Was it one of the lines of code which you pasted? Or some other line somewhere else in your code?
One thing I noticed, reading your code, is this:
You don't use
executeQueryto perform aDELETEstatement. You useexecuteorexecuteUpdateto perform aDELETEstatement. ADELETEstatement does not return aResultSet