my question is how can I show a date already stored in my BD in a JDATECHOOSER? I have a JFRAME in which it has a series of fields and I have a JDATECHOOSER in which I need to load the stored date previously. The method I use to load the data is as follows:
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);
int año = jdcFechaVencimiento.getCalendar().get(Calendar.YEAR);
int mes = jdcFechaVencimiento.getCalendar().get(Calendar.MONTH);
int dia = jdcFechaVencimiento.getCalendar().get(Calendar.DAY_OF_MONTH);
String fecha = año+"/"+mes+"/"+dia;
producto.setFechaVencimiento(fecha);
producto.setImage(fileImagen);
producto.guardar();
}
My method get
public void obtener(int idProd) {
List arrayCboCategoria = new ArrayList();
List arrayCboProveedor = new ArrayList();
try {
Connection miComando = AdministradorConfiguracion.obtenerComandoMySql();
CallableStatement obtenerCliente = miComando.prepareCall("call obtener_producto(?)");
obtenerCliente.setInt(1, idProd);
obtenerCliente.execute();
ResultSet rs = obtenerCliente.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.setDateFormatString("fechaVencimiento");
}
} 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) {
if (arrayCboProveedor.size() > 0) {
jcboCategoria.setModel(new DefaultComboBoxModel(arrayCboCategoria.toArray()));
jcboProveedores.setModel(new DefaultComboBoxModel(arrayCboProveedor.toArray()));
}
}
}
When wanting to modify a product I get java.lang.NullPointerException in line int año = jdcFechaVencimiento.getCalendar().get(Calendar.YEAR);
. My attribute of class product is type String
dateVencement , that's why I transform the date to string
when I store it, but I now need to show it, read it already store.
I would greatly appreciate your help. Thanks again.