Help SWT table and Database [message #523590] |
Fri, 26 March 2010 23:31 |
Eclipse User |
|
|
|
Hello, everyone
I am a new user in eclipse. I have a trouble with SWT table and database. The table can display all records from mysql database, but I want to delete particular row from the table and also compatible record will be dropped in mysql database.
Any help will be appreciated. Thanks a lot. Here are my code for Delete button:
btnDelete.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int select = table.getSelectionIndex();
try {
Class.forName("com.mysql.jdbc.Driver");
Cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Invdatabase","root","12345");
Ps = Cn.prepareStatement("Delete from Employee where EmployeeID='"+select+"'");
Ps.executeUpdate();
if(select>-1){
final Listener changeTableItemHeight = new Listener() {
public void handleEvent(Event event) {
event.height = (int)(event.gc.getFontMetrics().getHeight() * 1.5);
}
};
table.removeListener(SWT.MeasureItem, changeTableItemHeight);
table.clear(select);
table.remove(select);
table.addListener(SWT.MeasureItem, changeTableItemHeight);
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
|
|
|
Powered by
FUDForum. Page generated in 0.02400 seconds