private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      if (jTable1.getSelectedRow()==-1)
        {
            JOptionPane.showMessageDialog(this, "Select a search item to check out");
            return;
        }
        if (jTable1.getSelectedRowCount() > 1)
        {
         JOptionPane.showMessageDialog(this, "Error. Multiple items selected");
            return;
        }
        int row = jTable1.getSelectedRow();
        
        if(jTable1.getValueAt(row, 0)== null) {
          JOptionPane.showMessageDialog(this, "Select a search item to check out");
            return;       
        }
        
        
         
         
        //when paid already
        if((boolean)jTable1.getValueAt(row, 2) == true )
                { JOptionPane.showMessageDialog(this, "Already paid"); return;   } 
         
        //when not paid
        else
        {
            try{
         Class.forName("com.mysql.jdbc.Driver");    
         conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/library_management", "root", "welcome6" );
         
         String s = "select date_in from book_loans where loan_id =?";
         
        PreparedStatement ps1 = conn.prepareStatement(s);
        ps1.setInt(1, Integer.parseInt(jTable1.getValueAt(row,0).toString()));
        
        ResultSet rs1 = ps1.executeQuery(); 
        
        while (rs1.next())
        {
            //if book not returned
            if(rs1.getObject(1)==null)
            {
                JOptionPane.showMessageDialog(this, "Item not returned back yet");
                return;          
            }
            
            //if book returned
            else
            {
                
                     s = "update fines set paid = true where loan_id=?";
                     PreparedStatement ps2 = conn.prepareStatement(s);
                     ps2.setInt( 1 ,Integer.parseInt(jTable1.getValueAt(row,0).toString()) );
                    int x= ps2.executeUpdate();  
                    
                    if(x==1) { 
                     JOptionPane.showMessageDialog(this, "Successfully updated");
                     jTable1.setValueAt(true, row, 2);
                        
                    }
             
            }
            }
            
           
         
          conn.close();
         }
          catch(SQLException ex) {
			System.out.println("Error in connection: " + ex.getMessage());
		}
        catch (ClassNotFoundException ex)
        {
            System.out.println("Class not found:" + ex.getMessage());
        } 
                 
        
            }
    
            
            
           
        
    }//GEN-LAST:event_jButton1ActionPerformed