private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
        int value = jList1.getSelectedIndex();
        int i = 0, bookcode = 0;
        try {

            String query = "SELECT bookcode FROM books order by bookcode;";
            ResultSet rs = MyQueries.excQuery(query);
            while (rs.next())
            {

                if (i == value) // check to ensure column index(mysql) and imageindex(jList1 index) match.
                {
                    bookcode = rs.getInt("bookcode");
                    break;
                }
                i++;
            }
            myClasses.Connections.close(); // Close connection to prevent Database lock
        } catch (Exception e) 
        {
        }
        try {

            String query = "SELECT * FROM books where bookcode ='" + bookcode + "';";
            ResultSet rs = MyQueries.excQuery(query);
            rs.next();

            String bookname = rs.getString("bookname");
            String author = rs.getString("author");
            String rdate = rs.getString("releasedate");
            int pages = rs.getInt("pages");
            String genre = rs.getString("genre");
            String review = rs.getString("review");
            l1.setIcon(new ImageIcon(path + "images\\" + bookcode + ".jpg"));
            myClasses.Connections.close(); // Close connection to prevent Database lock

            File dir = new File(path + "images/" + bookcode + ".jpg");
            if (!dir.canRead()) {
                ResultSet rs1 = MyQueries.excQuery("select imgURL from books where bookcode=" + bookcode + ";");
                rs1.next();
                String url = rs1.getString("imgURL");
                URL url1 = new URL(url);
                l1.setIcon(Img.resizedplusImageIcon(url1, 200, 300));
                myClasses.Connections.close(); // Close connection to prevent Database lock
                
                //write the Img on the drive
                Image img = Img.resizedplusImage(url1, 200, 300);
                BufferedImage resizedImage = (BufferedImage) img;
                try {
                    new File(path + "\\images").mkdirs();
                    ImageIO.write(resizedImage, "jpg", new File(path + "images\\" + bookcode + ".jpg"));
                } catch (java.io.IOException f) {
                    JOptionPane.showMessageDialog(null, f.getMessage());
                }
            }
            l2.setText(bookcode + "");
            l3.setText(bookname);
            l4.setText(author);
            l5.setText(rdate);
            l6.setText("" + pages);
            l7.setText(genre);
            ta1.setText(review);
        } catch (Exception e) {
            logger.error("Error Description:", e);
        }
    }//GEN-LAST:event_jList1ValueChanged