import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class TableDataTesting {



private Table table;

private static Connection connect;
private static Statement statement;
private static ResultSet resultSet;

/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
TableDataTesting window = new TableDataTesting();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setLayout(new GridLayout(1, false));
shell.setSize(450, 300);
shell.setText("SWT Application");
{
table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
table.setHeaderVisible(true);
table.setItemCount(100);
table.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;

try{
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/EmployeeDatabase","root","12345");
System.out.println("Connecting succesfully");
statement = connect.createStatement();
resultSet = statement.executeQuery("Select * from EMPLOYEE");
while(resultSet.next()){
item.setText(new String[]{resultSet.getString(1),resultSet.getString(2),res ultSet.getString(3),resultSet.getString(4)});
}
}catch(Exception e){
System.out.println("Cannot connect to database server");
}

}
});

table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
{
TableColumn tblclmnEno = new TableColumn(table, SWT.NONE);
tblclmnEno.setWidth(100);
tblclmnEno.setText("Eno");
}
{
TableColumn tblclmnEname = new TableColumn(table, SWT.NONE);
tblclmnEname.setWidth(100);
tblclmnEname.setText("Ename");
}
{
TableColumn tblclmnAge = new TableColumn(table, SWT.NONE);
tblclmnAge.setWidth(100);
tblclmnAge.setText("Age");
}
{
TableColumn tblclmnPosition = new TableColumn(table, SWT.NONE);
tblclmnPosition.setWidth(100);
tblclmnPosition.setText("Position");
}

}

shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}

}

************************************************** *************************
I've used the tool to developer this small application normally. And the major point here that is "How can I display all records from my database into a table row by row without creating more TableItem"
I've tried so much but still get the last record:confused:. So I really need your help.

My mysql database is like this:

Eno Ename Age Position
1001 David 32 Programer
1002 Tom 30 Programer
1003 Thomas 34 Web developer

Thanks for your watching
Best regards