I am between the sword and the wall, I get the following error No value specified for parameter 10 when wanting to load the date stored in the DB in a JDateChooser. The error occurs when I load my product edit form, which I use the loadData () method that fills the JFrame fields.
private void cargarDatos() {
obtener(idModificado);
producto.setProducto(jtxtProducto.getText());
producto.setCantidad(Double.valueOf(jtxtCantidad.getText()));
producto.setPrecioCosto(Double.valueOf(jtxtPrecioCosto.getText()));
producto.setPrecioVenta(Double.valueOf(jtxtPrecioVenta.getText()));
producto.setMarca(jtxtMarca.getText());
producto.setDescripcion(jtxtDescripcion.getText());
Categoria cboCat = (Categoria)jcboCategoria.getSelectedItem();
int idCat = cboCat.getIdcategoria();
producto.setIdcategoria(idCat);
Proveedor cbo = (Proveedor) jcboProveedores.getSelectedItem();
int id = cbo.getIdproveedor();
producto.setIdproveedor(id);
SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");
String fecha = formatoFecha.format(jdcFechaVencimiento.getDate());
producto.setFechaVencimiento(fecha);
System.out.println(fecha);
producto.setImage(fileImagen);
producto.guardar();
}
The get () method is the one that brings what is stored in my BD and passes it through the id parameters of the product.
public void obtener(int idProd) {
List arrayCboCategoria = new ArrayList();
List arrayCboProveedor = new ArrayList();
try {
Connection miComando = AdministradorConfiguracion.obtenerComandoMySql();
CallableStatement obtenerProducto = miComando.prepareCall("call obtener_producto(?)");
obtenerProducto.setInt(1, idProd);
obtenerProducto.execute();
ResultSet rs = obtenerProducto.executeQuery();
while (rs.next()) {
jtxtIdProducto.setText(String.valueOf(rs.getInt("idproducto")));
jtxtProducto.setText(rs.getString("producto"));
jtxtCantidad.setText(rs.getString("cantidad"));
jtxtPrecioCosto.setText(rs.getString("precio_costo"));
jtxtPrecioVenta.setText(rs.getString("precio_venta"));
jtxtMarca.setText(rs.getString("marca"));
jtxtDescripcion.setText(rs.getString("descripcion"));
arrayCboCategoria.add(new Categoria(rs.getInt("idcategoria"), rs.getString("categoria")));
arrayCboProveedor.add(new Proveedor(rs.getInt("idproveedor"), rs.getString("nombre")));
jdcFechaVencimiento.setDate(new Date(rs.getDate("fechaVencimiento").getTime())); //Trae la fecha de la BD.
Blob blob = rs.getBlob(13);
if (blob != null) {
byte[] data = blob.getBytes(1, (int)blob.length());
try {
img = ImageIO.read(new ByteArrayInputStream(data));
ImageIcon icono = new ImageIcon(img);
lblImagenVisor.setIcon(icono);
} catch (Exception e) {
}
} else {
lblImagenVisor.setText("Sin Imagen");
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Error al intentar obtener el producto:\n"
+ e, "Error en la operación", JOptionPane.ERROR_MESSAGE);
}
if (arrayCboCategoria.size() > 0) {
jcboCategoria.setModel(new DefaultComboBoxModel(arrayCboCategoria.toArray()));
}
if (arrayCboProveedor.size() > 0) {
jcboProveedores.setModel(new DefaultComboBoxModel(arrayCboProveedor.toArray()));
}
}
When I run the project and I want to edit a product when loading the JFrame I get No value specified for parameter 10 which corresponds to the expiration date. When I accept the error, I execute the JFrame with all the data loaded correctly as you can see in the image.
But I do not know why I get that error if filling in the form fills the fields.
My method save is:
public void guardar() {
try {
Connection miComando = AdministradorConfiguracion.obtenerComandoMySql();
CallableStatement insertarProducto = miComando.prepareCall("call insertar_Producto(?,?,?,?,?,?,?,?,?,?)");
insertarProducto.setString(1, producto);
insertarProducto.setDouble(2, cantidad);
insertarProducto.setDouble(3, precioCosto);
insertarProducto.setDouble(4, precioVenta);
insertarProducto.setString(5, marca);
insertarProducto.setString(6, descripcion);
insertarProducto.setInt(7, idcategoria);
insertarProducto.setInt(8, idproveedor);
insertarProducto.setString(9, fechaVencimiento);
if (this.image != null) {
insertarProducto.setBinaryStream(10, image);
}else{
this.image = null;
}
if (this.idproducto != 0) {
CallableStatement modificarProducto = miComando.prepareCall("call modificar_producto(?,?,?,?,?,?,?,?,?,?,?)");
modificarProducto.setInt(1, idproducto);
modificarProducto.setString(2, producto);
modificarProducto.setDouble(3, cantidad);
modificarProducto.setDouble(4, precioCosto);
modificarProducto.setDouble(5, precioVenta);
modificarProducto.setString(6, marca);
modificarProducto.setString(7, descripcion);
modificarProducto.setInt(8, idcategoria);
modificarProducto.setInt(9, idproveedor);
modificarProducto.setString(10, fechaVencimiento);
if (this.image != null) {
insertarProducto.setBinaryStream(11, image);
}else {
this.image = null;
}
if (modificarProducto.executeUpdate() == 1) {
JOptionPane.showMessageDialog(null, "Producto modificado correctamente.", "Producto modificado", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Ha ocurrido un error al modificar el producto.", "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
this.idproducto = insertarProducto.executeUpdate();
if (idproducto > 0) {
JOptionPane.showMessageDialog(null, "Producto guardado correctamente.", "Producto insertado", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Ha ocurrido un error al guardar producto.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Error al intentar almacenar el producto:\n"
+ e, "Error en la operación", JOptionPane.ERROR_MESSAGE);
}
}
My class attributes.
int idproducto;
String producto;
double cantidad;
double precioCosto;
double precioVenta;
String marca;
String descripcion;
int idcategoria;
int idproveedor;
String fechaVencimiento;
FileInputStream image;
The Date_Vance field is of type DATETIME
in my BD.
My procedure get_product is:
CREATE DEFINER='root'@'localhost' PROCEDURE 'obtener_producto'(IN id int)
BEGIN
SELECT P.idproducto,
producto,
cantidad,
precio_costo,
precio_venta,
marca,
descripcion,
P.idcategoria,
C.categoria,
P.idproveedor,
PV.nombre,
fechaVencimiento,
imagen
FROM Producto P LEFT OUTER JOIN Categoria C
ON P.idcategoria = C.idcategoria LEFT OUTER JOIN Proveedor PV
ON P.idproveedor = PV.idproveedor
WHERE P.idproducto=id;
END
I really can not find the reason for the error, I would appreciate your help. Thanks again.