[SLUG] More Java Help

From: Russ Wright (rwrigh10@tampabay.rr.com)
Date: Sun Dec 21 2003 - 19:37:40 EST


Wel Sluggers my homework is going well however I hit a snag:

All help/suggestions appreciated!

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

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:51:56 EDT