title: Password to Confirm then Continue
body: <p><strong>EDIT :</strong> iam using Netbeans 8.0.1</p>
  
  <p>I've been days trying to search for a solution I tried jdialog and other things and couldn't help I hope you guys help me. 
  I noticed that after the user set the passwords and I set the <code>fechadesalida = null</code>, in my Database MySQL it will save all the text field as empty spaces.</p>
  
  <p>When the java application starts <code>accion = "insertar";</code>
  First of all I fill the TextFields, then I click this button </p>
  
  <pre><code>     private void btnGuardarSalidaActionPerformed(java.awt.event.ActionEvent evt) {                                                 
  
      if (cboCamion.getSelectedItem() != null) {
          if (cboChofer.getSelectedItem() != null) {
              if (T_SalidaKm.getText().trim().length() != 0) {
                  if (T_FechaSalida.getText().trim().length() != 0) {
                      ChoferLogin Chofer = new ChoferLogin();
                      Chofer.a = ((String) cboChofer.getSelectedItem());
                      Chofer.setVisible(true);
                  } else {
                      JOptionPane.showMessageDialog(null, "Inserte la Fecha");
                  }
              } else {
                  JOptionPane.showMessageDialog(null, "Seleccione el Km Salida");
              }
          } else {
              JOptionPane.showMessageDialog(null, "Seleccione el Chofer");
          }
      } else {
          JOptionPane.showMessageDialog(null, "Seleccione el Camion");
      }
  
  }    
  </code></pre>
  
  <p>then another class jframe popup , here the user insert his password then the bottun is cicked </p>
  
  <pre><code>    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      ChoferLog();
  
  
  } 
  </code></pre>
  
  <p>this is the method ChoferLog();
          public void ChoferLog() {</p>
  
  <pre><code>    String sql4 = " Select * from choferes where chofer=? and Password=?";
  
      try {
          pst = con.prepareStatement(sql4);
          pst.setString(1, a);
          pst.setString(2, T_Password.getText());
  
          rs = pst.executeQuery();
  
          if (rs.next()) {
              JOptionPane.showMessageDialog(null, "Confirmado");
              viajes.GuardarSalida();
              this.dispose();
  
          } else {
              JOptionPane.showMessageDialog(null, "La Contrasena es incorrecto");
          }
  
      } catch (SQLException | HeadlessException e) {
          JOptionPane.showMessageDialog(null, "Error" + e);
      }
  
      dispose();
  }
  </code></pre>
  
  <p>this is the method GuadarSalida(); from class Viajes</p>
  
  <pre><code>     void GuardarSalida() {
      switch (accion) {
          case "insertar":
              sql = "insert into viajes(camion,chofer,kmsalida,acompanhante,"
                      + "viatico,destino,cargadediesel,litros,fechadesalida,"
                      + "bascula,peaje)"
                      + " values (?,?,?,?,?,?,?,?,?,?,?) ";
              break;
          case "modificar":
              sql = "Update viajes set "
                      + "camion= ?,"
                      + "chofer= ?,"
                      + "kmsalida= ?,"
                      + "acompanhante= ?,"
                      + "viatico= ?,"
                      + "destino= ?,"
                      + "cargadediesel= ?,"
                      + "litros= ?,"
                      + "fechadesalida= ? ,"
                      + "bascula= ?,"
                      + "peaje= ? "
                      + " where idviajes = " + id;
              break;
      }
      sql = "insert into viajes(camion,chofer,kmsalida,acompanhante,"
              + "viatico,destino,cargadediesel,litros,fechadesalida,"
              + "bascula,peaje)"
              + " values (?,?,?,?,?,?,?,?,?,?,?) ";
  
      try {
  
          day = T_FechaSalida.getText().substring(0, 2);
          month = T_FechaSalida.getText().substring(3, 5);
          year = T_FechaSalida.getText().substring(6);
          pst = con.prepareStatement(sql);
          pst.setString(1, (String) cboCamion.getSelectedItem());
          pst.setString(2, (String) cboChofer.getSelectedItem());
          pst.setString(3, T_SalidaKm.getText());
          pst.setString(4, (String) cboAcompanhante.getSelectedItem());
          pst.setString(5, T_Viatico.getText());
          pst.setString(6, T_Destino.getText());
          pst.setString(7, T_CargadeDiesel.getText());
  
          if (T_CantDiesel.getText().isEmpty()) {
              pst.setString(8, null);
          } else {
              pst.setString(8, T_CantDiesel.getText());
          }
  
          pst.setString(9, year + "-" + month + "_" + day);
          pst.setString(10, T_Bascula.getText());
          pst.setString(11, T_Peaje.getText());
          pst.executeUpdate();
  
          TablaDeEspera();
          LimpiarSalida();
          JOptionPane.showMessageDialog(null, "Se Cargo Con Exito !", "Guardar", JOptionPane.INFORMATION_MESSAGE);
      } catch (SQLException ex) {
          JOptionPane.showMessageDialog(null, "No Se Cargo Los Datos " + ex);
      }
  
  }
  </code></pre>
  
  <p>and I get this problem, please help I've been days searching and couldn't find solution</p>
  
  <pre><code>    Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
  at java.lang.String.substring(String.java:1950) at java.lang.String.substring(String.java:1950)
  at Viaje.Viajes.GuardarSalida(Viajes.java:353)
  at Viaje.ChoferLogin.ChoferLog(ChoferLogin.java:61)
  at Viaje.ChoferLogin.jButton1ActionPerformed(ChoferLogin.java:197)
  at Viaje.ChoferLogin.access$300(ChoferLogin.java:22)
  at Viaje.ChoferLogin$3.actionPerformed(ChoferLogin.java:116)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
  at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
  at java.awt.Component.processMouseEvent(Component.java:6525)
  at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
  at java.awt.Component.processEvent(Component.java:6290)
  at java.awt.Container.processEvent(Container.java:2234)
  at java.awt.Component.dispatchEventImpl(Component.java:4881)
  at java.awt.Container.dispatchEventImpl(Container.java:2292)
  at java.awt.Component.dispatchEvent(Component.java:4703)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
  at java.awt.Container.dispatchEventImpl(Container.java:2278)
  at java.awt.Window.dispatchEventImpl(Window.java:2739)
  at java.awt.Component.dispatchEvent(Component.java:4703)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
  at java.awt.EventQueue.access$400(EventQueue.java:97)
  at java.awt.EventQueue$3.run(EventQueue.java:697)
  at java.awt.EventQueue$3.run(EventQueue.java:691)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
  at java.awt.EventQueue$4.run(EventQueue.java:719)
  at java.awt.EventQueue$4.run(EventQueue.java:717)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
  </code></pre>