我想要一个教程或方法,以便我可以突出显示从 mysql db 获取其数据的 Jtable 中的一行,然后单击编辑按钮,以便它启动一个表单,我可以使用该表单来编辑该行然后保存。我使用了一种有效的方法,但它引发了很多异常,所以我认为这是一个糟糕的设计。
编辑:我还不想使用绑定。我想编写我能理解的基本代码。
编辑2:这是我调用来获取我在编辑查询中使用的键..我突出显示该行并调用此函数:
int id = ((Number) model.getValueAt(jTable1.getSelectedRow(), 0)).intValue() ;
函数体不是我写的 这是ResultSetTableModel
文件的一部分
public Object getValueAt( int row, int column )
throws IllegalStateException
{
// ensure database connection is available
if ( !dbConnection.isConnectedToDatabase() )
throw new IllegalStateException( "Not Connected to Database" );
// obtain a value at specified ResultSet row and column
try
{
getResultSet().absolute( row + 1 );
return getResultSet().getObject( column + 1 );
} // end try
catch ( SQLException sqlException )
{
System.out.println("Exception from here dude");
sqlException.printStackTrace();
} // end catch
return ""; // if problems, return empty string object
} // end method getValueAt
这里抛出了一个结果集关闭异常,我知道原因是因为我之前使用了相同的结果集来填充表格。所以我想要一个不同的选择。