library.restore.java Source code

Java tutorial

Introduction

Here is the source code for library.restore.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package library;

import javax.swing.JFileChooser;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Row;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author kimani kogi
 */
public class restore extends javax.swing.JFrame {
    String students;
    String books;
    String tt;
    String loaned;
    String loanedcourse;
    String libfines;

    /**
     * Creates new form restore
     */
    public restore() {
        initComponents();
        try {
            selectname();
        } catch (Exception ex) {
            Logger.getLogger(LOAN.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("academic.png")));
        this.setTitle(tt);
    }

    public void selectname() throws Exception {
        java.sql.Connection con = getConnection();
        Statement st2 = con.createStatement();

        ResultSet res7 = st2.executeQuery("SELECT name FROM libprefrence  ");
        while (res7.next()) {
            tt = (res7.getString("name"));
        }
        st2.close();
        res7.close();
        con.close();
    }

    public java.sql.Connection getConnection() {
        java.sql.Connection con = null;
        try {
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/library", "root", "123ERYcog.");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return con;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jtfFileLocation = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jtfFileLocation1 = new javax.swing.JTextField();
        jtfFileLocation2 = new javax.swing.JTextField();
        jtfFileLocation3 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jtfFileLocation4 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(51, 51, 255));

        jButton1.setText("STUDENTS RECORDS");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("BOOKS RECORDS");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jtfFileLocation3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfFileLocation3ActionPerformed(evt);
            }
        });

        jButton3.setText("COURSE BOOKS LOANED");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("LIBRARY FINES LIST");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("LOANED BOOKS");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jtfFileLocation4, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                        .addComponent(jtfFileLocation3, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jtfFileLocation2)
                        .addComponent(jtfFileLocation, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jtfFileLocation1, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 218,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 218,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 218,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 218,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 218,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));
        jPanel1Layout
                .setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jtfFileLocation).addComponent(jButton1,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 54,
                                                Short.MAX_VALUE)
                                        .addComponent(jtfFileLocation1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jtfFileLocation2, javax.swing.GroupLayout.PREFERRED_SIZE, 51,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 51,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, 0)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jtfFileLocation3).addComponent(jButton3,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jtfFileLocation4).addComponent(jButton4,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))
                                .addGap(54, 54, 54)));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String fileSeparator = System.getProperty("file.separator");
        JFileChooser chooser = new JFileChooser();
        //set JFileChooser default path
        chooser.setCurrentDirectory(new java.io.File("."));
        //set JFileChooser title
        chooser.setDialogTitle("open");
        //use as you need DIRECTORIES_ONLY, FILES_ONLY etc
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        //false, if you want to view all kind of file type in JFileChooser
        //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            //write selected path inside JTextField
            jtfFileLocation.setText(chooser.getSelectedFile().getPath() + fileSeparator);
            //students=getText(chooser.getSelectedFile().getPath()+fileSeparator);
            students = jtfFileLocation.getText();
            System.out.println("" + students + "");
        } else {
            System.out.println("No Selection");
        }
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root",
                    "123ERYcog.");
            con.setAutoCommit(false);
            PreparedStatement pstm = null;
            // this.fileurlp = this.student.replace("\\", "\\\\");
            FileInputStream input = new FileInputStream("" + students + "");
            POIFSFileSystem fs = new POIFSFileSystem(input);
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            Row row;
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                row = sheet.getRow(i);
                String sid = row.getCell(0).getStringCellValue();
                String fname = row.getCell(1).getStringCellValue();
                String lastname = row.getCell(2).getStringCellValue();
                String form = row.getCell(3).getStringCellValue();
                String classs = row.getCell(4).getStringCellValue();
                String imgurlK = row.getCell(5).getStringCellValue();

                String imgurl = imgurlK.replace("\\", "\\\\");
                String sql = "INSERT INTO students VALUES('" + sid + "','" + fname + "','" + lastname + "','" + form
                        + "','" + classs + "','" + imgurl + "')";
                pstm = (PreparedStatement) con.prepareStatement(sql);
                pstm.execute();
                System.out.println("Import rows " + i);
            }
            con.commit();
            pstm.close();
            con.close();
            input.close();
            JOptionPane.showMessageDialog(null, "Success import excel to mysql table");
            System.out.println("Success import excel to mysql table");
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "error import excel to mysql table");
            System.out.println(ex);
        } catch (IOException ioe) {
            System.out.println(ioe);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jtfFileLocation3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfFileLocation3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfFileLocation3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        String fileSeparator = System.getProperty("file.separator");
        JFileChooser chooser = new JFileChooser();
        //set JFileChooser default path
        chooser.setCurrentDirectory(new java.io.File("."));
        //set JFileChooser title
        chooser.setDialogTitle("open");
        //use as you need DIRECTORIES_ONLY, FILES_ONLY etc
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        //false, if you want to view all kind of file type in JFileChooser
        //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            //write selected path inside JTextField
            jtfFileLocation1.setText(chooser.getSelectedFile().getPath() + fileSeparator);
            //students=getText(chooser.getSelectedFile().getPath()+fileSeparator);
            books = jtfFileLocation1.getText();
            System.out.println("" + books + "");
        } else {
            System.out.println("No Selection");
        }
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root",
                    "123ERYcog.");
            con.setAutoCommit(false);
            PreparedStatement pstm = null;
            // this.fileurlp = this.student.replace("\\", "\\\\");
            FileInputStream input = new FileInputStream("" + books + "");
            POIFSFileSystem fs = new POIFSFileSystem(input);
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            Row row;
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                row = sheet.getRow(i);
                String id = row.getCell(0).getStringCellValue();
                String title = row.getCell(1).getStringCellValue();
                String ediion = row.getCell(2).getStringCellValue();
                String status = row.getCell(3).getStringCellValue();

                //String imgurl =imgurlK.replace("\\", "\\\\");
                String sql = "INSERT INTO books VALUES('" + id + "','" + title + "','" + ediion + "','" + status
                        + "')";
                pstm = (PreparedStatement) con.prepareStatement(sql);
                pstm.execute();
                System.out.println("Import rows " + i);
            }
            con.commit();
            pstm.close();
            con.close();
            input.close();
            JOptionPane.showMessageDialog(null, "Success import excel to mysql table");
            System.out.println("Success import excel to mysql table");
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "error import excel to mysql table");
            System.out.println(ex);
        } catch (IOException ioe) {
            System.out.println(ioe);
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        String fileSeparator = System.getProperty("file.separator");
        JFileChooser chooser = new JFileChooser();
        //set JFileChooser default path
        chooser.setCurrentDirectory(new java.io.File("."));
        //set JFileChooser title
        chooser.setDialogTitle("open");
        //use as you need DIRECTORIES_ONLY, FILES_ONLY etc
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        //false, if you want to view all kind of file type in JFileChooser
        //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            //write selected path inside JTextField
            jtfFileLocation2.setText(chooser.getSelectedFile().getPath() + fileSeparator);
            //students=getText(chooser.getSelectedFile().getPath()+fileSeparator);
            loaned = jtfFileLocation2.getText();
            System.out.println("" + loaned + "");
        } else {
            System.out.println("No Selection");
        }
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root",
                    "123ERYcog.");
            con.setAutoCommit(false);
            PreparedStatement pstm = null;
            // this.fileurlp = this.student.replace("\\", "\\\\");
            FileInputStream input = new FileInputStream("" + loaned + "");
            POIFSFileSystem fs = new POIFSFileSystem(input);
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            Row row;
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                row = sheet.getRow(i);
                String no = row.getCell(0).getStringCellValue();
                String bid = row.getCell(1).getStringCellValue();
                String sid = row.getCell(2).getStringCellValue();
                String title = row.getCell(3).getStringCellValue();

                String fname = row.getCell(4).getStringCellValue();
                String lname = row.getCell(5).getStringCellValue();

                String form = row.getCell(6).getStringCellValue();
                String classs = row.getCell(7).getStringCellValue();
                String edition = row.getCell(8).getStringCellValue();
                String updated_at = row.getCell(9).getStringCellValue();
                //String title = row.getCell(3).getStringCellValue();

                String sql = "INSERT INTO loaned VALUES('" + no + "','" + bid + "','" + sid + "','" + title + "','"
                        + fname + "','" + lname + "','" + form + "','" + classs + "','" + edition + "','"
                        + updated_at + "')";
                pstm = (PreparedStatement) con.prepareStatement(sql);
                pstm.execute();
                System.out.println("Import rows " + i);
            }
            con.commit();
            pstm.close();
            con.close();
            input.close();
            JOptionPane.showMessageDialog(null, "Success import excel to mysql table");
            System.out.println("Success import excel to mysql table");
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "error import excel to mysql table");
            System.out.println(ex);
        } catch (IOException ioe) {
            System.out.println(ioe);
        }

    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        String fileSeparator = System.getProperty("file.separator");
        JFileChooser chooser = new JFileChooser();
        //set JFileChooser default path
        chooser.setCurrentDirectory(new java.io.File("."));
        //set JFileChooser title
        chooser.setDialogTitle("open");
        //use as you need DIRECTORIES_ONLY, FILES_ONLY etc
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        //false, if you want to view all kind of file type in JFileChooser
        //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            //write selected path inside JTextField
            jtfFileLocation3.setText(chooser.getSelectedFile().getPath() + fileSeparator);
            //students=getText(chooser.getSelectedFile().getPath()+fileSeparator);
            loanedcourse = jtfFileLocation3.getText();
            System.out.println("" + loanedcourse + "");
        } else {
            System.out.println("No Selection");
        }
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root",
                    "123ERYcog.");
            con.setAutoCommit(false);
            PreparedStatement pstm = null;
            // this.fileurlp = this.student.replace("\\", "\\\\");
            FileInputStream input = new FileInputStream("" + loanedcourse + "");
            POIFSFileSystem fs = new POIFSFileSystem(input);
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            Row row;
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                row = sheet.getRow(i);
                String no = row.getCell(0).getStringCellValue();
                String bid = row.getCell(1).getStringCellValue();
                String sid = row.getCell(2).getStringCellValue();
                String title = row.getCell(3).getStringCellValue();

                String fname = row.getCell(4).getStringCellValue();
                String lname = row.getCell(5).getStringCellValue();

                String form = row.getCell(6).getStringCellValue();
                String classs = row.getCell(7).getStringCellValue();
                String edition = row.getCell(8).getStringCellValue();
                String updated_at = row.getCell(9).getStringCellValue();
                //String title = row.getCell(3).getStringCellValue();

                String sql = "INSERT INTO loanedcourse VALUES('" + no + "','" + bid + "','" + sid + "','" + title
                        + "','" + fname + "','" + lname + "','" + form + "','" + classs + "','" + edition + "','"
                        + updated_at + "')";
                pstm = (PreparedStatement) con.prepareStatement(sql);
                pstm.execute();
                System.out.println("Import rows " + i);
            }
            con.commit();
            pstm.close();
            con.close();
            input.close();
            JOptionPane.showMessageDialog(null, "Success import excel to mysql table");
            System.out.println("Success import excel to mysql table");
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "error import excel to mysql table");
            System.out.println(ex);
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        String fileSeparator = System.getProperty("file.separator");
        JFileChooser chooser = new JFileChooser();
        //set JFileChooser default path
        chooser.setCurrentDirectory(new java.io.File("."));
        //set JFileChooser title
        chooser.setDialogTitle("open");
        //use as you need DIRECTORIES_ONLY, FILES_ONLY etc
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        //false, if you want to view all kind of file type in JFileChooser
        //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            //write selected path inside JTextField
            jtfFileLocation4.setText(chooser.getSelectedFile().getPath() + fileSeparator);
            //students=getText(chooser.getSelectedFile().getPath()+fileSeparator);
            libfines = jtfFileLocation4.getText();
            System.out.println("" + libfines + "");
        } else {
            System.out.println("No Selection");
        }
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root",
                    "123ERYcog.");
            con.setAutoCommit(false);
            PreparedStatement pstm = null;
            // this.fileurlp = this.student.replace("\\", "\\\\");
            FileInputStream input = new FileInputStream("" + libfines + "");
            POIFSFileSystem fs = new POIFSFileSystem(input);
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            Row row;
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                row = sheet.getRow(i);
                String pid = row.getCell(0).getStringCellValue();
                String adm = row.getCell(1).getStringCellValue();
                String amount = row.getCell(2).getStringCellValue();
                String day = row.getCell(3).getStringCellValue();
                String status = row.getCell(4).getStringCellValue();

                //String imgurl =imgurlK.replace("\\", "\\\\");
                String sql = "INSERT INTO libfines VALUES('" + pid + "','" + adm + "','" + amount + "','" + day
                        + "','" + status + "')";
                pstm = (PreparedStatement) con.prepareStatement(sql);
                pstm.execute();
                System.out.println("Import rows " + i);
            }
            con.commit();
            pstm.close();
            con.close();
            input.close();
            JOptionPane.showMessageDialog(null, "Success import excel to mysql table");
            System.out.println("Success import excel to mysql table");
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "error import excel to mysql table");
            System.out.println(ex);
        } catch (IOException ioe) {
            System.out.println(ioe);
        }

    }//GEN-LAST:event_jButton4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(restore.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(restore.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(restore.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(restore.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new restore().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jtfFileLocation;
    private javax.swing.JTextField jtfFileLocation1;
    private javax.swing.JTextField jtfFileLocation2;
    private javax.swing.JTextField jtfFileLocation3;
    private javax.swing.JTextField jtfFileLocation4;
    // End of variables declaration//GEN-END:variables
}