Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/06/2016, 08:37
Larry16
 
Fecha de Ingreso: abril-2016
Ubicación: Acayucan, Veracruz
Mensajes: 10
Antigüedad: 8 años, 1 mes
Puntos: 0
Respuesta: Los datos de un jtable no se guardan en la base de datos

claro que si amig@... aqui te dejo el codigo que estoy usando. todo eso esta adentro de un boton.

try {

String NºDeVenta = "";

String[] datos = new String[7];

int fila = tbAbono.getSelectedRow();

if (fila == -1) {
JOptionPane.showMessageDialog(null, "SELECCIONE EL PRODUCTO QUE DESEA ABONAR");
} else {

String NVenta = tbAbono.getValueAt(filas, 0).toString();
String UltimoAbo = tbAbono.getValueAt(filas, 1).toString();
String ClaArti = tbAbono.getValueAt(filas, 2).toString();
String Arti = tbAbono.getValueAt(filas, 3).toString();
String TV = tbAbono.getValueAt(filas, 4).toString();
String abo = txtAbono.getText();
String restante= tbAbono.getValueAt(filas, 6).toString();

datos[0] = NVenta;
datos[1] = UltimoAbo;
datos[2] = ClaArti;
datos[3] = Arti;
datos[4] = TV;
datos[5] = abo;
datos[6] = restante;

for (int i = 0; i < tbAbono.getColumnCount(); i++) {
modelo.setValueAt(datos[i], filas, i);}

restaa();

PreparedStatement pst = cn.prepareStatement("UPDATE abonos SET Fecha='"
+ txtFecha.getText() + "',IdArticulo='"
+ ClaArti + "',NombreArti='"
+ Arti + "',IdCliente='"
+ txtclaveclie.getText() + "',NombreClie='"
+ txtnombre.getText() + "',TotalDeVenta='"
+ TV + "',Restante='"
+ restante + "',Abono='"
+ txtAbono.getText() + "' WHERE IdVenta='" + NVenta + "'");
int n = pst.executeUpdate();
if (n > 0) {
JOptionPane.showMessageDialog(null, "EL ABONO SE REALIZO CORRECTAMENTE");
}

}//1

} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Error al momento de abonar", JOptionPane.ERROR_MESSAGE);
}