
RECUPERAR DATOS DE JTABLE
Publicado por DARIO (2 intervenciones) el 18/11/2014 03:48:26
Hola amigos, si pudieran ayudarme con este problema que se me ha presentado al momento de querer recuperar los datos de mi JTable.
Estoy ingresando los datos de una BD en SQL a una JTable, al momento de visualizar la tabla lo hace correctamente, el problema lo tengo al querer pasarlos a un xml, unicamente pasa la ultima fila y no todas las filas que esten en el JTable.
Como soluciono esto???, gracias.
//ESTE ES EL CODIGO COMO LO ESTOY HACIENDO
String numfactu = this.factura.getText().toString();
Conexion con = new Conexion();
ResultSet r = con.SeleccionarArticulo(numfactu);
DefaultTableModel dfm = new DefaultTableModel();
this.tablaArticulos.setModel(dfm);
dfm.setColumnIdentifiers(new Object[]{
"CODIGO",
"ARTICULO",
"CANTIDAD",
"VALOR",
try
{
while(r.next())
{
dfm.addRow(new Object[] {
r.getString("codart"),
r.getString("nomart"),
r.getDouble("cantid"),
r.getDouble("totren"),
}
}catch (Exception e)
{}
for(int i=0;i<tablaArticulos.getRowCount();i++)
{
FacturaDetalle d1 = new FacturaDetalle();
d1.setCodigoPrincipal((String) tablaArticulos.getValueAt(i,1));
d1.setDescripcion((String) tablaArticulos.getValueAt(i,2));
d1.setCantidad((Double) tablaArticulos.getValueAt(i,3));
d1.setPrecioUnitario((Double) tablaArticulos.getValueAt(i,4));
List<FacturaDetalle> listaDetalles = new ArrayList<FacturaDetalle>();
listaDetalles.add(d1);
factura.setDetalle(listaDetalles);
}
Estoy ingresando los datos de una BD en SQL a una JTable, al momento de visualizar la tabla lo hace correctamente, el problema lo tengo al querer pasarlos a un xml, unicamente pasa la ultima fila y no todas las filas que esten en el JTable.
Como soluciono esto???, gracias.
//ESTE ES EL CODIGO COMO LO ESTOY HACIENDO
String numfactu = this.factura.getText().toString();
Conexion con = new Conexion();
ResultSet r = con.SeleccionarArticulo(numfactu);
DefaultTableModel dfm = new DefaultTableModel();
this.tablaArticulos.setModel(dfm);
dfm.setColumnIdentifiers(new Object[]{
"CODIGO",
"ARTICULO",
"CANTIDAD",
"VALOR",
try
{
while(r.next())
{
dfm.addRow(new Object[] {
r.getString("codart"),
r.getString("nomart"),
r.getDouble("cantid"),
r.getDouble("totren"),
}
}catch (Exception e)
{}
for(int i=0;i<tablaArticulos.getRowCount();i++)
{
FacturaDetalle d1 = new FacturaDetalle();
d1.setCodigoPrincipal((String) tablaArticulos.getValueAt(i,1));
d1.setDescripcion((String) tablaArticulos.getValueAt(i,2));
d1.setCantidad((Double) tablaArticulos.getValueAt(i,3));
d1.setPrecioUnitario((Double) tablaArticulos.getValueAt(i,4));
List<FacturaDetalle> listaDetalles = new ArrayList<FacturaDetalle>();
listaDetalles.add(d1);
factura.setDetalle(listaDetalles);
}
Valora esta pregunta


0