i've followed some stackoverflow responses to this problem and every answer i found contributed a bit to solve the problem, however i'm still stuck.
I still can't update a table cell with the Date Type, i click the cell and edit it, but when i press Enter it won't update, it won't even let me leave the cell it just displays a red border around it. I would appreciate some insight, thank you.
getColumnClass method:
@Override
public Class getColumnClass(int column) throws IllegalStateException {
String columnName;
if (!connectedToDatabase) {
throw new IllegalStateException("Not Connected to Database");
}
columnName = getColumnName(column);
if(columnName.equals("id")) {
return java.lang.Integer.class;
}
switch (table) {
case 0:
if (columnName.equals("dn") || columnName.equals("ade")) {
return java.util.Date.class;
} else {
return java.lang.String.class;
}
default:
try {
String className = metaData.getColumnClassName(column + 1);
return Class.forName(className);
} catch (SQLException | ClassNotFoundException ex) {
return Object.class;
}
}
}
getValueAt method:
@Override
public Object getValueAt(int row, int column) throws IllegalStateException {
if (!connectedToDatabase) {
throw new IllegalStateException("Not Connected to Database");
}
try {
resultSet.absolute(row + 1);
return resultSet.getObject(column + 1);
} catch (SQLException ex) {
return "";
}
}
setValueAt method:
@Override
public void setValueAt(Object value, int rowIndex, int columnIndex) {
String columnName = getColumnName(columnIndex);
java.sql.Date sqlDate;
switch (table) {
case 0:
if (columnName.equals("dn") || columnName.equals("de")) {
sqlDate = new java.sql.Date(((java.util.Date) value).getTime());
try {
resultSet.absolute(rowIndex + 1);
resultSet.updateDate(columnIndex + 1, sqlDate);
resultSet.updateRow();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
try {
resultSet.absolute(rowIndex + 1);
resultSet.updateString(columnIndex + 1, (String) value);
resultSet.updateRow();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
this.fireTableCellUpdated(rowIndex, columnIndex);
}