Tengo este código que es el formulario de mi ventana para ingresar un mozo a una base de datos que esta creada desde wamp
.
El problema es que no me envía la consulta, la conexión parece estar bien
Les dejo el código por aquí
package Ventanas;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import Clases.BaseDatos;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
public class ingresoMozo extends JFrame {
private JPanel contentPane;
private BaseDatos Palomos=null;
private JTextField txtCed;
private JTextField txtNom;
private JTextField txtApe;
private JTextField txtSueldo;
private JTextField txtTel;
private BaseDatos coco;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ingresoMozo frame = new ingresoMozo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ingresoMozo() {
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds(100, 100, 650, 650);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblCedula = new JLabel("C\u00E9dula");
lblCedula.setBounds(23, 99, 46, 14);
contentPane.add(lblCedula);
JLabel lblNombre = new JLabel("Nombre");
lblNombre.setBounds(23, 124, 46, 14);
contentPane.add(lblNombre);
JLabel lblApellido = new JLabel("Apellido");
lblApellido.setBounds(23, 150, 46, 14);
contentPane.add(lblApellido);
JLabel lblTelfono = new JLabel("Tel\u00E9fono");
lblTelfono.setBounds(23, 176, 46, 14);
contentPane.add(lblTelfono);
JLabel lblMozoAadidoCorrectamenteerror = new JLabel("Mozo a\u00F1adido correctamente/error");
lblMozoAadidoCorrectamenteerror.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblMozoAadidoCorrectamenteerror.setBounds(23, 239, 219, 20);
contentPane.add(lblMozoAadidoCorrectamenteerror);
JLabel lblIngresarMozo = new JLabel("Datos de mozo");
lblIngresarMozo.setFont(new Font("Tahoma", Font.BOLD, 14));
lblIngresarMozo.setBounds(49, 52, 112, 20);
contentPane.add(lblIngresarMozo);
JLabel lblIngresoDeMozo = new JLabel("Ingreso de mozo");
lblIngresoDeMozo.setFont(new Font("Tahoma", Font.BOLD, 16));
lblIngresoDeMozo.setBounds(260, 11, 160, 28);
contentPane.add(lblIngresoDeMozo);
txtCed = new JTextField();
txtCed.setBounds(78, 100, 129, 20);
contentPane.add(txtCed);
txtCed.setColumns(10);
txtNom = new JTextField();
txtNom.setBounds(78, 125, 129, 20);
contentPane.add(txtNom);
txtNom.setColumns(10);
txtApe = new JTextField();
txtApe.setBounds(78, 150, 129, 20);
contentPane.add(txtApe);
txtApe.setColumns(10);
String cedula, telefono;
String nombre, apellido;
nombre=txtNom.getText().toString();
apellido=txtApe.getText().toString();
cedula=txtCed.getText().toString();
Integer ced=Integer.parseInt(cedula);
telefono=txtTel.getText().toString();
Integer tel=Integer.parseInt(telefono);
String consulta1 = "INSERT INTO 'personas'('nombre', 'apellido', 'telefono', 'ci') VALUES ('" + nombre + "', '" + apellido + "' ,'" + tel + "', '" + ced + "');";
JButton btnAceptar = new JButton("Aceptar");
btnAceptar.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
coco.ejecutar(consulta1);
}});
btnAceptar.setBounds(104, 285, 89, 23);
contentPane.add(btnAceptar);
JButton btnLimpiarDatos = new JButton("Limpiar datos");
btnLimpiarDatos.setBounds(260, 285, 112, 23);
contentPane.add(btnLimpiarDatos);
JLabel lblSueldo = new JLabel("Sueldo");
lblSueldo.setBounds(23, 201, 46, 14);
contentPane.add(lblSueldo);
txtSueldo = new JTextField();
txtSueldo.setBounds(78, 198, 129, 20);
contentPane.add(txtSueldo);
txtSueldo.setColumns(10);
txtTel = new JTextField();
txtTel.setBounds(75, 173, 86, 20);
contentPane.add(txtTel);
txtTel.setColumns(10);
}
}
Les dejo mi clase de Base de datos que tengo la conexion y la funcion para ejecutar una consulta
public Connection getConexion() {
return conexion;
}
public void setConexion(Connection conexion) {
this.conexion = conexion;
}
public boolean ejecutar(String sql) {
try {
Statement sentencia = getConexion().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
sentencia.executeUpdate(sql);
sentencia.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return true;
}
El error que me aparece en pantalla es
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Ventanas.ingresoMozo.(ingresoMozo.java:144) at Ventanas.Indice$1.mouseClicked(Indice.java:53) at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)