Okay I know there are other messages about this but I could not find one to solve my problem.
I have a Jform. On the form I have placed a JScrollPane on top of the JScrollPane I have placed a swing.JTable.
I'm using netbeans 3.5.1 and using the gui creator which created a function called initcomponents() In there this is how netbeans set up the controls:
JTblDonations.setModel(new javax.swing.table.DefaultTableModel(
new Object [][]
{
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new
String []
{
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(JTblDonations);
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 270, 390, 100));
Now later in my code I have a function that gets some data from a MySQL table and puts it in a class level recordset called m_RSDonations. Then I want to display this recordset in the JTable created in the initComponents() function described above. My code is below. How DO I get the records to display??
Thanks in advance
Russ
My Code:
private void displayDonations()
/********************************************************************************
* Function Name: displayDonations
* //based somewhat on code from Deitel and Dietel
* Purpose: to display the donations on the interface
*
* Inputs ResultSet rS
* Outputs: grid rs
*
* change log
* date initials description
* 12/12/2003 rww iniial creatiion
*
***********************************************************************************/
{
gridColumns = new Vector();
gridRows = new Vector();
try
{ //move to first record
m_RSDonations.next();
//get the column headers
ResultSetMetaData rs = m_RSDonations.getMetaData();
for (int i = 1; i <= rs.getColumnCount(); ++i)
gridColumns.addElement(rs.getColumnName(i));
do
{
gridRows.addElement(getNextRow(m_RSDonations,rs));
}
//if records exist build a grid
while (m_RSDonations.next());
//create table
//******WHAT DO I DO HERE???
JTblDonations
//***********************
}
catch(SQLException sqlx)
{
sqlx.printStackTrace();
}
}
private Vector getNextRow(ResultSet rS, ResultSetMetaData rs) throws SQLException
{
Vector currentRow = new Vector();
for (int i = 1; i <= rs.getColumnCount(); ++i)
if (rs.getColumnType(i) == Types.VARCHAR)
{
currentRow.addElement(rS.getString(i));
}
else
{
//Ab.connectField.setText("Type was: " + rs.getColumnTypeName(i));
}
return currentRow;
} //end getnextrow