
Error introducir dato auto_increment
Publicado por esi92 (37 intervenciones) el 25/10/2016 21:30:02
Hola,
Al rellenar todos mis campos y pulsar el botón "Nuevo" se añaden los datos a la BD y FUNCIONA.
Pero el caso es que CodigoCliente lo tengo en la BD como auto_increment Y noNull entonces si no le introduzco nada me da error... ¿Como podria hacerlo?
Error:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at proyecto_integrado.Clientes.jButtonNuevoActionPerformed(Clientes.java:538)
at proyecto_integrado.Clientes.access$200(Clientes.java:16)
at proyecto_integrado.Clientes$3.actionPerformed(Clientes.java:150)
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.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)
Al rellenar todos mis campos y pulsar el botón "Nuevo" se añaden los datos a la BD y FUNCIONA.
Pero el caso es que CodigoCliente lo tengo en la BD como auto_increment Y noNull entonces si no le introduzco nada me da error... ¿Como podria hacerlo?
Error:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at proyecto_integrado.Clientes.jButtonNuevoActionPerformed(Clientes.java:538)
at proyecto_integrado.Clientes.access$200(Clientes.java:16)
at proyecto_integrado.Clientes$3.actionPerformed(Clientes.java:150)
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.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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
private void jButtonNuevoActionPerformed(java.awt.event.ActionEvent evt) {
String CodCli = jTextFieldCodigoCliente.getText();
int CodigoCliente = Integer.parseInt(CodCli);
String Dni = jTextFieldDNI.getText();
String Nombre = jTextFieldNombre.getText();
String Direccion = jTextFieldDireccion.getText();
String Tlf = jTextFieldTelefono.getText();
int Telefono = Integer.parseInt(Tlf);
String FAX = jTextFieldFax.getText();
int Fax = Integer.parseInt(FAX);
String Pais = jTextFieldPais.getText();
String Provincia = jTextFieldProvincia.getText();
String Ciudad = jTextFieldCiudad.getText();
String OtrosDatos = jTextAreaOtrosDatos.getText();
//Para guardar los datos introducidos en los campos a la base de datos
try {
PreparedStatement pst = cn.prepareStatement("INSERT INTO clientes (CodigoCliente,Dni,Nombre,Direccion,Telefono,Fax,Pais,Provincia,Ciudad,OtrosDatos) VALUES(?,?,?,?,?,?,?,?,?,?)");
pst.setInt(1, CodigoCliente);
pst.setString(2, Dni);
pst.setString(3, Nombre);
pst.setString(4, Direccion);
pst.setInt(5, Telefono);
pst.setInt(6, Fax);
pst.setString(7, Pais);
pst.setString(8, Provincia);
pst.setString(9, Ciudad);
pst.setString(10, OtrosDatos);
pst.executeUpdate();
} catch(Exception ex) {
Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex);
}
}
Valora esta pregunta


0