private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed

        if (jTable1.getSelectedRow()==-1)
        {
            JOptionPane.showMessageDialog(this, "Select a search item to check in");
            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, "Search and choose an item to return back");
            return;
        }  

        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/library_management", "root", "welcome6" );
           
            
            
            String s2 = "update book_loans set date_in = ? where loan_id= ? and date_in IS NULL "; 
            PreparedStatement pst2 = conn.prepareStatement( s2 );
            
             java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());
             pst2.setTimestamp(1,date);
             pst2.setObject(2,jTable1.getValueAt(row, 0));
            
            int x = pst2.executeUpdate();
            
            if (x==1)
            {
             JOptionPane.showMessageDialog(this, "Successfully checked in");
             jButton2.doClick();}
             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_jButton4ActionPerformed