Necesitaría ayuda para resolver este error, teóricamente debería funcionar ya que la tabla muestra que tiene registros ingresados (cuando pulso el botón para cargar los mismos), pero el error me devuelve que el array está vacío. Agradecería si alguien pudiera darme la solución. Considero que el error se encuentra en el método actualizarDatos(), pero según mi criterio el mismo debería funcionar correctamente. También dejo el método que utilizo para cargar la tabla, por si consideran que el error se encuentra allí (aunque no lo creo).
JButton btnNewButton_1 = new JButton("Filtrar");
btnNewButton_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
PreparedStatement st=DatabaseManager.getConnection().prepareStatement("SELECT * FROM RECLAMO WHERE ESTADO=? AND USUARIO=?");
String estado = (String)comboBox.getSelectedItem();
String usuariodesdelogin = textField.getText();
st.setString(1, estado);
st.setString(2, usuariodesdelogin);
ResultSet rs = st.executeQuery();
ResultSetMetaData rsMd = rs.getMetaData();
int numColumnas = rsMd.getColumnCount();
DefaultTableModel modelo = new DefaultTableModel();
table.setModel(modelo);
for(int i=1; i<=numColumnas; i++) {
modelo.addColumn(rsMd.getColumnLabel(i));
}
while (rs.next()) {
Object [] fila = new Object[numColumnas];
for(int y=0; y<numColumnas; y++) {
fila [y]=rs.getObject(y+1);
}
modelo.addRow(fila);
AutoSizeColumnas aSc = new AutoSizeColumnas();
aSc.resizeColumnWidth(table);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
comboBox.setSelectedIndex(0);
}catch (SQLException e1) {
e1.printStackTrace();
}
}
});
public void actualizarDatos() {
int fila = table.getSelectedRow();
int id = Integer.parseInt(table.getValueAt(fila, 0).toString());
String titulo = table.getValueAt(fila, 1).toString();
String descripcion = table.getValueAt(fila, 2).toString();
String fecha_reclamo = table.getValueAt(fila, 3).toString();
String hora = table.getValueAt(fila, 4).toString();
String nombre_evento = table.getValueAt(fila, 5).toString();
String nombre_actividad = table.getValueAt(fila, 6).toString();
int semestre = Integer.parseInt(this.table.getValueAt(fila, 7).toString());
String fecha_actividad = table.getValueAt(fila, 8).toString();
String docente = table.getValueAt(fila, 9).toString();
int creditos = Integer.parseInt(this.table.getValueAt(fila, 10).toString());
String usuario = table.getValueAt(fila, 11).toString();
String estado = table.getValueAt(fila, 12).toString();
try {
PreparedStatement actu = DatabaseManager.getConnection().prepareStatement("UPDATE RECLAMO SET TITULO='"+titulo+"', DESCRIPCION='"+descripcion+"', FECHA_RECLAMO='"+fecha_reclamo+"', HORA='"+hora+"', "
+ "NOMBRE_EVENTO='"+nombre_evento+"', NOMBRE_ACTIVIDAD='"+nombre_actividad+"', SEMESTRE='"+semestre+"', FECHA_ACTIVIDAD='"+fecha_actividad+"', DOCENTE='"+docente+"', CREDITOS='"+creditos+"', USUARIO='"+usuario+"', ESTADO='"+estado+"' "
+ "WHERE ID_RECLAMO='"+id+"'");
actu.executeUpdate();
} catch (Exception e) {
System.out.println(e);
JOptionPane.showMessageDialog(null, "No se pudo actualizar");
}
}
}
fila [y]=rs.getObject(y+1);
, no deberías aumentar ay
en ese punto, puesy
irá aumentando en la iteracción del bucle al ponery++
, por tanto, debes ponerlo así:fila [y]=rs.getObject(y);