我正在使用此代码保存JTable
个内容:
@override
public void editingStopped(ChangeEvent ce) {
PreparedStatement pstmt = null;
try {
int row = getEditingRow();
int column = getEditingColumn();
DefaultStyledDocument doc = (DefaultStyledDocument) getCellEditor().getCellEditorValue();
doc.setDocumentFilter(null);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject((DefaultStyledDocument) doc);
oos.flush();
byte[] data = bos.toByteArray();
oos.close();
bos.close();
String query = "update BOX_ROWS "
+ "set COLUMN1= ? "
+ "where BOX_ID=" + ID
+ " and INDEX=" + row;
pstmt = ReseachAssistantUI.conn.prepareStatement(query);
pstmt.setObject(1, data);
pstmt.executeUpdate();
doc.setDocumentFilter(new MyDocumentFilter());
} catch (SQLException ex) {
Logger.getLogger(MyTable.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
JOptionPane.showMessageDialog(null, "MyTable - " + ex.getMessage());
} catch (IOException ex) {
Logger.getLogger(MyTable.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
JOptionPane.showMessageDialog(null, "MyTable - " + ex.getMessage());
} finally {
DBUtil.closePreparedStatement(pstmt, MyTable.class.getName());
}
super.editingStopped(ce);
}
它在 Windows 上运行良好。但是,当我在 Mac OS X 上运行我的应用程序时,会出现以下消息:
MyTable - com.apple.laf.AquaComboBoxUI
表弹出编辑器在工具栏上确实有2个组合框,但我看不出它们与此异常有什么关系。有谁知道为什么会抛出这个异常?序列化对象的方式有问题吗?