org.myorg.insertar.insertarSabanaTopComponent.java Source code

Java tutorial

Introduction

Here is the source code for org.myorg.insertar.insertarSabanaTopComponent.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 org.myorg.insertar;

import org.myorg.dao.TablasDao;
import org.myorg.conexion.Conexion;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//org.myorg.insertar//insertarSabana//EN", autostore = false)
@TopComponent.Description(preferredID = "insertarSabanaTopComponent",
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "editor", openAtStartup = true)
@ActionID(category = "Window", id = "org.myorg.insertar.insertarSabanaTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(displayName = "#CTL_insertarSabanaAction", preferredID = "insertarSabanaTopComponent")
@Messages({ "CTL_insertarSabanaAction=Insertar tablas en BD", "CTL_insertarSabanaTopComponent=INSERTAR DATOS",
        "HINT_insertarSabanaTopComponent=Gestion de insercin de tablas directas" })
public final class insertarSabanaTopComponent extends TopComponent {

    // ..........................................................

    public String tablaDatos[][] = new String[2000][50];
    public String nombres[] = new String[50];
    public String tipos[] = new String[50];

    // ..........................................................

    File nombre = null;
    // ..........................................................

    public int nDatos = 0;
    public int nColumnas = 0;
    public String sLogTxt = "";

    // ..........................................................

    public String plogin = "";
    public String ppassword = "";
    public String bdStr = "";
    public String urlStr = "";

    // ..........................................................

    public insertarSabanaTopComponent() {
        initComponents();
        setName(Bundle.CTL_insertarSabanaTopComponent());
        setToolTipText(Bundle.HINT_insertarSabanaTopComponent());
        putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
        System.setProperty("netbeans.buildnumber", "2.0.1");

        System.setProperty("netbeans.projectname", "CONTRACT - SERNOVEN");

    }

    /**
     * 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel51 = new javax.swing.JPanel();
        jLabel174 = new javax.swing.JLabel();
        jLabel175 = new javax.swing.JLabel();
        jLabel176 = new javax.swing.JLabel();
        jLabel177 = new javax.swing.JLabel();
        bdname = new javax.swing.JTextField();
        host = new javax.swing.JTextField();
        login = new javax.swing.JTextField();
        passw = new javax.swing.JTextField();
        jButton22 = new javax.swing.JButton();
        jButton23 = new javax.swing.JButton();
        miBarra2 = new javax.swing.JScrollPane();
        miTabla2e = new javax.swing.JTable();
        jScrollPane12 = new javax.swing.JScrollPane();
        logAcciones = new javax.swing.JTextArea();
        jLabel178 = new javax.swing.JLabel();
        tabla = new javax.swing.JTextField();
        jLabel179 = new javax.swing.JLabel();
        jTextField127 = new javax.swing.JTextField();
        jLabel180 = new javax.swing.JLabel();
        jTextField128 = new javax.swing.JTextField();
        jProgressBar1 = new javax.swing.JProgressBar();
        jComboBox10 = new javax.swing.JComboBox();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel174, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jLabel174.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel175, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jLabel175.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel176, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jLabel176.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel177, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jLabel177.text")); // NOI18N

        bdname.setText(org.openide.util.NbBundle.getMessage(insertarSabanaTopComponent.class,
                "insertarSabanaTopComponent.bdname.text")); // NOI18N

        host.setText(org.openide.util.NbBundle.getMessage(insertarSabanaTopComponent.class,
                "insertarSabanaTopComponent.host.text")); // NOI18N

        login.setText(org.openide.util.NbBundle.getMessage(insertarSabanaTopComponent.class,
                "insertarSabanaTopComponent.login.text")); // NOI18N

        passw.setText(org.openide.util.NbBundle.getMessage(insertarSabanaTopComponent.class,
                "insertarSabanaTopComponent.passw.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButton22, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jButton22.text")); // NOI18N
        jButton22.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton22ActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jButton23, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jButton23.text")); // NOI18N
        jButton23.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton23ActionPerformed(evt);
            }
        });

        miTabla2e
                .setModel(new javax.swing.table.DefaultTableModel(
                        new Object[][] { { null, null, null, null }, { null, null, null, null },
                                { null, null, null, null }, { null, null, null, null } },
                        new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
        miBarra2.setViewportView(miTabla2e);

        logAcciones.setColumns(20);
        logAcciones.setRows(5);
        jScrollPane12.setViewportView(logAcciones);

        org.openide.awt.Mnemonics.setLocalizedText(jLabel178, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jLabel178.text")); // NOI18N

        tabla.setBackground(new java.awt.Color(204, 255, 204));

        org.openide.awt.Mnemonics.setLocalizedText(jLabel179, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jLabel179.text")); // NOI18N

        jTextField127.setText(org.openide.util.NbBundle.getMessage(insertarSabanaTopComponent.class,
                "insertarSabanaTopComponent.jTextField127.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel180, org.openide.util.NbBundle
                .getMessage(insertarSabanaTopComponent.class, "insertarSabanaTopComponent.jLabel180.text")); // NOI18N

        jTextField128.setText(org.openide.util.NbBundle.getMessage(insertarSabanaTopComponent.class,
                "insertarSabanaTopComponent.jTextField128.text")); // NOI18N

        jComboBox10.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "Seleccionar tabla...", "MAKRO RESIDENCIAL", "MAKRO PYMES", "LOCUCIONES RESIDENCIAL",
                        "LOCUCIONES PYMES", "CERTIFICACIONES RESIDENCIAL", "CERTIFICACIONES PYMES" }));
        jComboBox10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox10ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel51Layout = new javax.swing.GroupLayout(jPanel51);
        jPanel51.setLayout(jPanel51Layout);
        jPanel51Layout.setHorizontalGroup(jPanel51Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel51Layout.createSequentialGroup().addGroup(jPanel51Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(miBarra2)
                        .addGroup(jPanel51Layout.createSequentialGroup().addGap(31, 31, 31)
                                .addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel174)
                                        .addGroup(jPanel51Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel178).addComponent(jLabel176))
                                        .addComponent(jLabel179).addComponent(jLabel180))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel51Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(jTextField128,
                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
                                                .addComponent(jTextField127,
                                                        javax.swing.GroupLayout.Alignment.LEADING))
                                        .addGroup(jPanel51Layout.createSequentialGroup().addGroup(jPanel51Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(bdname, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 181,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(login, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 118,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(49, 49, 49)
                                                .addGroup(jPanel51Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel177).addComponent(jLabel175)))
                                        .addComponent(jComboBox10, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel51Layout
                                                .createSequentialGroup().addGroup(jPanel51Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(host, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                183, Short.MAX_VALUE)
                                                        .addComponent(passw))
                                                .addGap(50, 50, 50)
                                                .addGroup(jPanel51Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(jButton23,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE, 127,
                                                                Short.MAX_VALUE)
                                                        .addComponent(jButton22,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)))
                                        .addComponent(tabla, javax.swing.GroupLayout.PREFERRED_SIZE, 181,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 703,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 703,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 105, Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel51Layout.setVerticalGroup(jPanel51Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel51Layout.createSequentialGroup().addGroup(jPanel51Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel51Layout.createSequentialGroup().addGroup(jPanel51Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel51Layout.createSequentialGroup().addGap(24, 24, 24)
                                        .addGroup(jPanel51Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel174).addComponent(bdname,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel51Layout
                                        .createSequentialGroup().addContainerGap()
                                        .addGroup(jPanel51Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel175).addComponent(host,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel51Layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        2, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(jPanel51Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(login, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jLabel176)))
                                        .addComponent(passw, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel177))
                                .addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel51Layout.createSequentialGroup().addGap(5, 5, 5)
                                                .addGroup(jPanel51Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel178).addComponent(jComboBox10,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel51Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel179).addComponent(jTextField127,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGroup(jPanel51Layout.createSequentialGroup()
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(tabla, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel51Layout.createSequentialGroup().addContainerGap().addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                jPanel51Layout.createSequentialGroup().addComponent(jButton22)
                                                        .addGap(76, 76, 76))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel51Layout
                                                .createSequentialGroup()
                                                .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)))))
                        .addGroup(jPanel51Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel51Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel180)
                                        .addComponent(jTextField128, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButton23)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(miBarra2, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                        .addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 1683, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
                        .createSequentialGroup()
                        .addComponent(jPanel51, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 10, Short.MAX_VALUE))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 750, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
                        .createSequentialGroup().addContainerGap()
                        .addComponent(jPanel51, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
    }// </editor-fold>//GEN-END:initComponents

    private void jButton22ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton22ActionPerformed
        try {
            leerArchivoExel();
            mostrarDatosEnTabla();
        } catch (IOException ex) {
            //     Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton22ActionPerformed

    private void jButton23ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton23ActionPerformed
        // iniciaBarra();
        this.plogin = login.getText();
        this.plogin = this.plogin.trim();
        this.ppassword = passw.getText();
        this.ppassword = this.ppassword.trim();
        this.bdStr = bdname.getText();
        this.bdStr = this.bdStr.trim();
        this.urlStr = host.getText();
        this.urlStr = this.urlStr.trim();
        insertarDatosEnTabla2();
    }//GEN-LAST:event_jButton23ActionPerformed

    private void jComboBox10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox10ActionPerformed
        // ....................................... seleccionamos una tabla para insertar datos en ella.
        String str;
        str = jComboBox10.getSelectedItem().toString();
        str = str.trim();

        if (str.equals("MAKRO RESIDENCIAL")) {
            tabla.setText("t_makro_residencial");
        }
        if (str.equals("MAKRO PYMES")) {
            tabla.setText("t_makro_pymes");
        }
        if (str.equals("LOCUCIONES RESIDENCIAL")) {
            tabla.setText("t_locuciones_residencial");
        }
        if (str.equals("LOCUCIONES PYMES")) {
            tabla.setText("t_locuciones_pymes");
        }
        if (str.equals("CERTIFICACIONES RESIDENCIAL")) {
            tabla.setText("t_tabla_certificaciones_nominal");
        }
        if (str.equals("CERTIFICACIONES PYMES")) {
            tabla.setText("t_tabla_certificaciones_nominal_pymes");
        }

    }//GEN-LAST:event_jComboBox10ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField bdname;
    private javax.swing.JTextField host;
    private javax.swing.JButton jButton22;
    private javax.swing.JButton jButton23;
    private javax.swing.JComboBox jComboBox10;
    private javax.swing.JLabel jLabel174;
    private javax.swing.JLabel jLabel175;
    private javax.swing.JLabel jLabel176;
    private javax.swing.JLabel jLabel177;
    private javax.swing.JLabel jLabel178;
    private javax.swing.JLabel jLabel179;
    private javax.swing.JLabel jLabel180;
    private javax.swing.JPanel jPanel51;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JTextField jTextField127;
    private javax.swing.JTextField jTextField128;
    private javax.swing.JTextArea logAcciones;
    private javax.swing.JTextField login;
    private javax.swing.JScrollPane miBarra2;
    private javax.swing.JTable miTabla2e;
    private javax.swing.JTextField passw;
    private javax.swing.JTextField tabla;

    // End of variables declaration//GEN-END:variables
    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
    // ------------------------------------------------------------------------------------------------------

    public void leerArchivoExel() throws IOException {

        File abre = abrirArchivo();
        JOptionPane.showMessageDialog(null, "\nEl nombre del archivo es:" + abre, "AVISO",
                JOptionPane.WARNING_MESSAGE);

        this.nombre = abre;
        // An excel file name. You can create a file name with a full
        // path information.
        //
        //       String filename = "test.xls";
        String filename = this.nombre.getAbsolutePath();
        //
        // Create an ArrayList to store the data read from excel sheet.
        //
        List sheetData = new ArrayList();
        FileInputStream fis = null;
        try {
            //
            // Create a FileInputStream that will be use to read the
            // excel file.
            //
            fis = new FileInputStream(filename);
            //
            // Create an excel workbook from the file system.
            //
            HSSFWorkbook workbook = new HSSFWorkbook(fis);
            //
            // Get the first sheet on the workbook.
            //
            HSSFSheet sheet = workbook.getSheetAt(0);
            //
            // When we have a sheet object in hand we can iterator on
            // each sheet's rows and on each row's cells. We store the
            // data read on an ArrayList so that we can printed the
            // content of the excel to the console.
            //
            Iterator rows = sheet.rowIterator();
            while (rows.hasNext()) {
                HSSFRow row = (HSSFRow) rows.next();

                Iterator cells = row.cellIterator();
                List data = new ArrayList();
                while (cells.hasNext()) {
                    HSSFCell cell = (HSSFCell) cells.next();
                    //  System.out.println("Aadiendo Celda: " + cell.toString());
                    data.add(cell);
                }
                sheetData.add(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                fis.close();
            }
        }
        showExelData(sheetData);
        procesaDatosEntrada(sheetData);

    }

    // ------------------------------------------------------------------------------------------------------------    
    public void showExelData(List sheetData) {
        //
        // Iterates the data and print it out to the console.
        //

        for (int i = 0; i < sheetData.size(); i++) {
            List list = (List) sheetData.get(i);
            for (int j = 0; j < list.size(); j++) {
                Cell cell = (Cell) list.get(j);
                if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.print(cell.getNumericCellValue());
                } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    System.out.print(cell.getRichStringCellValue());
                } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                    System.out.print(cell.getBooleanCellValue());
                }
                if (j < list.size() - 1) {
                    System.out.print(", ");
                }
            }
            System.out.println("");
        }
    }

    // ------------------------------------------------------------------------------------------------------------ 
    private File abrirArchivo() {
        JFileChooser fileChooser = new JFileChooser();

        fileChooser.showOpenDialog(this);
        File abre = fileChooser.getSelectedFile();
        JOptionPane.showMessageDialog(null, "\nEl nombre del archivo es:" + abre, "AVISO",
                JOptionPane.WARNING_MESSAGE);
        return abre;
    }
    // -------------------------------------------------------------------------------------------------------------

    public void procesaDatosEntrada(List sheetData) {
        //
        // Iterates the data and print it out to the console.
        //
        int cnt = 0;
        int fProblema = 0;
        int nTipos = 0;
        SimpleDateFormat formatDateJava = new SimpleDateFormat("dd-MM-yyyy");

        HSSFRichTextString richTextString;
        // ...........................................................................................
        for (int i = 0; i < sheetData.size(); i++) {

            List list = (List) sheetData.get(i);
            System.out.println(i + " -> Tenemos Exel con " + list.size() + " columnas");

            // ...........................................................................................
            if (cnt == 0) { // CARGAMOS LOS NOMBRES DE LOS CAMPOS

                for (int j = 0; j < list.size(); j++) {

                    Cell cell = (Cell) list.get(j);
                    // ............................................................
                    System.out.println("Tipo  Nombre =" + cell.getCellType());
                    if (cell.getCellType() == Cell.CELL_TYPE_STRING) {

                        richTextString = (HSSFRichTextString) cell.getRichStringCellValue();

                        this.nombres[j] = richTextString.getString();
                        System.out.println("Cargando Nombre =" + this.nombres[j]);
                    }
                }
                this.nColumnas = list.size();
                System.out.println("Numero de campos=" + this.nColumnas);

            }
            // ...........................................................................................
            if (cnt == 1) { // CARGAMOS LOS TIPOS DE LOS CAMPOS
                nTipos = list.size();
                for (int j = 0; j < list.size(); j++) {

                    Cell cell = (Cell) list.get(j);

                    if (cell.getCellType() == Cell.CELL_TYPE_STRING) {

                        richTextString = (HSSFRichTextString) cell.getRichStringCellValue();

                        this.tipos[j] = richTextString.getString();
                    }
                    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {

                        this.tipos[j] = Double.toString(cell.getNumericCellValue());
                        System.out.println("Cargo this.tipos[" + j + "] = " + this.tipos[j]);

                    }

                }

            }
            // ...........................................................................................
            if (cnt > 1) { // CARGAMOS LOS DATOS
                System.out.println("------------CARGAMOS LOS DATOS -----------");
                if (nTipos != list.size()) {
                    this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2)
                            + ") -> HAY UN PROBLEMA :EL NMERO DE CAMPOS DEFINIDOS Y EL QUE CONTIENE LA L?NEA DE DATOS NO COINCIDE ("
                            + nTipos + "!=" + list.size() + ") \n";
                    //   fProblema = 2 ;
                }
                if (fProblema != 2) {

                    for (int j = 0; j < list.size(); j++) {

                        Cell cell = (Cell) list.get(j);

                        this.tablaDatos[cnt - 2][j] = "";
                        // ............................................................                                           
                        if (this.tipos[j].equals("4.0")) { // es un tipo fecha
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                            try {
                                this.tablaDatos[cnt - 2][j] = String.valueOf(sdf.format(cell.getDateCellValue()));
                            } catch (IllegalStateException e) {
                                this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2)
                                        + ") -> HAY UN PROBLEMA EL TIPO FECHA EN EL CAMPO: " + this.nombres[j]
                                        + "\n";
                                fProblema = 1;
                            }

                        } else {
                            // ............................................................
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                try {
                                    this.tablaDatos[cnt - 2][j] = Double.toString(cell.getNumericCellValue());
                                } catch (IllegalStateException e) {
                                    this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2)
                                            + ") -> HAY UN PROBLEMA EL TIPO DE DATO NUMERICO EN EL CAMPO: "
                                            + this.nombres[j] + "\n";
                                    fProblema = 1;
                                }

                            } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                                // ............................................................
                                try {
                                    richTextString = (HSSFRichTextString) cell.getRichStringCellValue();
                                    this.tablaDatos[cnt - 2][j] = richTextString.getString();
                                } catch (IllegalStateException e) {
                                    this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2)
                                            + ") ->HAY UN PROBLEMA EL TIPO DE DATO TEXTO EN EL CAMPO: "
                                            + this.nombres[j] + "\n";
                                    fProblema = 1;

                                }

                            } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                                // ............................................................
                                try {
                                    this.tablaDatos[cnt - 2][j] = Boolean.toString(cell.getBooleanCellValue());
                                } catch (IllegalStateException e) {
                                    this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2)
                                            + ") ->HAY UN PROBLEMA EL TIPO DE DATO BOOLEANO EN EL CAMPO: "
                                            + this.nombres[j] + "\n";
                                    fProblema = 1;
                                }

                            } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
                                // ............................................................
                                this.tablaDatos[cnt - 2][j] = "";

                            }
                        }

                    }

                    // ...........................................................................................

                }
                cnt++;
            } else { // Nos saltamos el procesamiento de esta lnea y seguimos contando.
                cnt++;
                fProblema = 0;
            }
        }

        // ...........................................................................................
        this.nDatos = cnt;
        System.out.println("----------- HE CARGADO " + this.nDatos + " REGISTROS ------------");
        this.sLogTxt += "----------- HE CARGADO " + this.nDatos + " REGISTROS  ------------" + "\n";
        logAcciones.setText(this.sLogTxt);
        if (fProblema == 0) {
            JOptionPane.showMessageDialog(null, "\nHE CARGADO:" + this.nDatos + " REGISTROS", "INFORMACIN",
                    JOptionPane.WARNING_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "\nSE HAN DETECTADO PROBLEMAS, SE CANCELA LA CARGA DE ARCHIVO EXEL",
                    "AVISO", JOptionPane.WARNING_MESSAGE);
        }
    }
    // -------------------------------------------------------------------------------------------------------------

    private void mostrarDatosEnTabla() {
        int i, j;
        String str = "";
        System.out.println("----COMIENZO EL FORMATEO CERTIFICACIONES---");
        this.sLogTxt += "----COMIENZO EL FORMATEO CERTIFICACIONES---" + "\n";
        logAcciones.setText(this.sLogTxt);
        DefaultTableModel model;
        model = new DefaultTableModel(); // definimos el objeto tableModel

        miTabla2e = new JTable(); // creamos la instancia de la tabla
        miTabla2e.setModel(model);

        for (i = 0; i < this.nColumnas; i++) {
            System.out.println("Proceso columna:" + i);
            str = this.nombres[i];
            str = str.trim();
            str = str.toUpperCase();
            model.addColumn(str);
        }

        miTabla2e.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        miTabla2e.getTableHeader().setReorderingAllowed(false);

        Object[] fila = new Object[this.nColumnas];
        // para llenar cada columna con lo datos almacenados
        for (i = 0; i < this.nDatos; i++) {
            for (j = 0; j < this.nColumnas; j++) {
                fila[j] = this.tablaDatos[i][j]; // es para cargar los datos en filas a la tabla modelo
            }
            model.addRow(fila);
        }

        System.out.println("----HE DEFINIDO FORMATO Y PASO A ASIGNAR---");

        this.sLogTxt += "----HE DEFINIDO FORMATO Y PASO A ASIGNAR---" + "\n";
        logAcciones.setText(this.sLogTxt);
        miBarra2.setViewportView(miTabla2e);

        str = Integer.toString(this.nDatos);
        jTextField127.setText(str); // proponemos numero de filas

        str = Integer.toString(this.nColumnas);
        jTextField128.setText(str); // proponemos numero de columnas

    }

    // --------------------------------------------------------------------------------------------------------------------------------
    private void insertarDatosEnTabla() {

        String sqlStr = "";
        String str;
        int i, j, k, cnt = 0;
        int estadoInsert = 0;

        TablasDao miTablaDao = new TablasDao();

        Conexion conex = new Conexion();
        // .....................................................................................................................
        if (conex != null) {

            final Thread t;
            //Inicializamos

            // .......................................................................
            for (k = 0; k < this.nDatos - 2; k++) {

                sqlStr = "INSERT INTO ";

                str = tabla.getText();
                str = str.trim();

                sqlStr = sqlStr + str + " (";

                for (i = 0; i < this.nColumnas - 1; i++) {

                    sqlStr = sqlStr + this.nombres[i].trim() + ",";

                }
                sqlStr = sqlStr + this.nombres[i].trim() + ") ";

                sqlStr = sqlStr + " VALUES (";

                for (i = 0; i < this.nColumnas - 1; i++) {

                    str = this.tablaDatos[k][i];
                    str = str.trim();
                    sqlStr = sqlStr + "'" + str + "', ";

                }

                str = this.tablaDatos[k][i];
                str = str.trim();
                sqlStr = sqlStr + "'" + str + "') ";

                System.out.println(k + "sqlStr = " + sqlStr);

                estadoInsert = miTablaDao.registrarFila(conex, this.plogin, this.ppassword, this.bdStr, this.urlStr,
                        sqlStr);

                this.sLogTxt += k + "sqlStr = " + sqlStr + "\n";
                logAcciones.setText(this.sLogTxt);
                System.out.println("Registro insertado ");

            }
            // .....................................................................................................................   
            conex.desconectar();
            // .....................................................................................................................   

        } else {
            JOptionPane.showMessageDialog(null, "Debes introducir login y password", "Advertencia",
                    JOptionPane.WARNING_MESSAGE);

        }

    }
    // --------------------------------------------------------------------------------------------------------------

    private void insertarDatosEnTabla2() {

        Runnable r = new t(this.nombres, this.tablaDatos, this.plogin, this.ppassword, this.bdStr, this.urlStr);

        new Thread(r).start();

    }

    // ----------------------------------------------------------------------------------------------------------------------------------
    public class t implements Runnable {

        public t(String nombres[], String tablaDatos[][], String plogin, String ppassword, String bdStr,
                String urlStr) {

        }

        //Implementamos el mtodo run()
        @Override
        public void run() {

            String sqlStr;
            String str;
            int i, j, k, cnt = 0, nDatos, nColumnas;
            int estadoInsert = 0;
            Conexion conex = new Conexion();

            // .....................................................................................................................
            if (conex != null) {

                TablasDao miTablaDao = new TablasDao();
                //Permite mostrar el valor del progreso
                jProgressBar1.setStringPainted(true);
                int x = 0;
                jProgressBar1.setMaximum(100);
                nDatos = Integer.valueOf(jTextField127.getText());
                nColumnas = Integer.valueOf(jTextField128.getText());

                // .......................................................................
                for (k = 0; k < nDatos - 2; k++) {

                    sqlStr = "INSERT INTO ";

                    str = tabla.getText();
                    str = str.trim();

                    sqlStr = sqlStr + str + " (";

                    for (i = 0; i < nColumnas - 1; i++) {

                        sqlStr = sqlStr + nombres[i].trim() + ",";

                    }
                    sqlStr = sqlStr + nombres[i].trim() + ") ";

                    sqlStr = sqlStr + " VALUES (";

                    for (i = 0; i < nColumnas - 1; i++) {

                        str = tablaDatos[k][i];
                        str = str.trim();
                        sqlStr = sqlStr + "'" + str + "', ";

                    }

                    System.out.println("tablaDatos[" + k + "][" + i + "]=" + tablaDatos[k][i]);

                    str = tablaDatos[k][i];
                    str = str.trim();
                    sqlStr = sqlStr + "'" + str + "') ";

                    System.out.println(k + "sqlStr = " + sqlStr);

                    estadoInsert = miTablaDao.registrarFila(conex, plogin, ppassword, bdStr, urlStr, sqlStr);

                    logAcciones.append(k + " --> sqlStr = " + sqlStr + "\n");

                    x = (k * 100) / nDatos;
                    jProgressBar1.setValue(x);

                }
                // .....................................................................................................................   
                conex.desconectar();
                jProgressBar1.setValue(0);
                jProgressBar1.setMaximum(0);
                jProgressBar1.setString("");

                JOptionPane.showMessageDialog(null, "La entrada de datos se ha concluido con exito!",
                        "Informacion", JOptionPane.WARNING_MESSAGE);

                // .....................................................................................................................   

            } else {
                JOptionPane.showMessageDialog(null, "Debes introducir login y password", "Advertencia",
                        JOptionPane.WARNING_MESSAGE);

            }

        }
    }
}