untitld untitld - 5 months ago 12
Java Question

How Could I show all the values on my wamp table to JTable

I want to show all the data from my Wamp server table to my JTable.
Only the first data will show. (I'm new to Java)

This program works perfectly using JTextField but on JTable it is not working.

using JTable:


Account Number/FirstName/MiddleName/LastName

1111-11 / Erwin / Walker / Miles


private class ListenviewDepositor implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
ListAccount.setVisible(true);
try
{
ResultSet result = null;

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager.getConnection(CONNECTION_URL);
Statement stmt = conn.createStatement();
try
{

result = stmt.executeQuery("SELECT * FROM mist1");
}
catch(SQLException e)
{
System.out.println("SQLException:" + e.getMessage() );
System.out.println("SQLState:" + e.getMessage() );
System.out.println("VendorError:" + e.getMessage() );
}
while(result.next())
{
String AccNum = result.getString("AccountNumber");
String fNtext = result.getString("FirstName");
String mNtext = result.getString("MiddleName");
String lNtext = result.getString("LastName");



String columnNames[] = { "Account Number ", "First Name", "Last Name","Middle Name" };
String dataValues[][]=

{
{AccNum,fNtext,lNtext,mNtext}

};

table = new JTable( dataValues, columnNames );

scrollPane = new JScrollPane( table );
ListAccount.add(scrollPane);

}

}
catch(Exception e)
{
System.out.println("Holy Crap" );
System.out.println( e.getMessage() );
e.printStackTrace();
System.out.println("Remember Mandatory Fields");
}
}
}

Answer

The problem is probably within the conditions of the loop.

while(result.next())
             {
                    String AccNum = result.getString("AccountNumber");
                    String fNtext = result.getString("FirstName");
                    String mNtext = result.getString("MiddleName");
                    String lNtext = result.getString("LastName");



                    String columnNames[] = { "Account Number ", "First Name", "Last Name","Middle Name" };
                    String dataValues[][]=

                    {
                        {AccNum,fNtext,lNtext,mNtext}

                    };

                    table = new JTable( dataValues, columnNames );

                    scrollPane = new JScrollPane( table );
                    ListAccount.add(scrollPane);

             }
Comments