java swt 数据库写的信息管理系统

①登录界面

package xitong;

import org.eclipse.swt.widgets.Display;


public class login {
protected Shell shell;
private Text text;
private Text text_2;


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


/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}


/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
Device display = null;
Image image=new Image(display,"H://sublime工作区/pictures/gz.jpg");
shell.setBackgroundImage(image);
shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
shell.setSize(450, 300);
shell.setText("登录界面");
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);

text = new Text(shell, SWT.BORDER);
text.setBounds(164, 85, 73, 26);

text_2 = new Text(shell, SWT.BORDER);
text_2.setEchoChar('*');
text_2.setBounds(164, 156, 73, 26);

Label label = new Label(shell, SWT.NONE);
label.setBounds(82, 88, 76, 20);
label.setText("\u7528\u6237\u540D");

Label label_2 = new Label(shell, SWT.NONE);
label_2.setBounds(82, 162, 76, 20);
label_2.setText("\u5BC6\u7801");

Button button = new Button(shell, SWT.NONE);
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
    if(text.getText().equals("lct")&&text_2.getText().equals("123")){
    shell.dispose();
    mainscreen window = new mainscreen();
    window.open();
    }
    else{
      MessageBox box=new MessageBox(shell,0); 
          box.setMessage("输入信息无效"); 
          box.open(); 
    }
}
});
button.setBounds(150, 199, 98, 30);
button.setText("\u767B\u5F55");

Label label_3 = new Label(shell, SWT.NONE);
label_3.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
label_3.setFont(SWTResourceManager.getFont("楷体", 16, SWT.BOLD));
label_3.setBounds(82, 0, 186, 41);
label_3.setText("\u5458\u5DE5\u7BA1\u7406\u7CFB\u7EDF");



}

}

②主界面

package xitong;


import java.sql.Connection;


public class mainscreen {
protected Shell shell,xianshishell,shell1;
protected Table table;
private Text text;
private Text text_1;
private Text text_2;
private Text text_3;
private Text text_4;
private Text text_5;


/**
* Launch the application.
* @param args
*/


/**
* Open the window.
* @wbp.parser.entryPoint
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}


/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 370);
shell.setText("主界面");
xianshishell=new Shell();
xianshishell.setSize(450, 300);
xianshishell.setText("显示界面");
Device display = null;
Image image=new Image(display,"H://sublime工作区/pictures/fj.jpg");
shell.setBackgroundImage(image);

table = new Table(xianshishell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
table.setBounds(0, 0, 465, 253);
table.setHeaderVisible(true);
table.setLinesVisible(true);
Button button_2 = new Button(shell, SWT.NONE);
button_2.setBounds(10, 0, 66, 43);
button_2.setText("\u5F55\u5165");

Button button_3 = new Button(shell, SWT.NONE);
button_3.setBounds(116, 3, 66, 37);
button_3.setText("\u67E5\u8BE2");

Button button_4 = new Button(shell, SWT.NONE);
button_4.setBounds(221, 3, 74, 37);
button_4.setText("\u4FEE\u6539");

Button button_5 = new Button(shell, SWT.NONE);
button_5.setBounds(358, 0, 74, 43);
button_5.setText("\u5220\u9664");

Label label = new Label(shell, SWT.NONE);
label.setText("\u59D3\u540D");
label.setBounds(72, 49, 35, 20);

text = new Text(shell, SWT.BORDER);
text.setBounds(168, 46, 74, 26);

Label label_1 = new Label(shell, SWT.NONE);
label_1.setText("\u7535\u8BDD");
label_1.setBounds(72, 86, 35, 20);

text_1 = new Text(shell, SWT.BORDER);
text_1.setBounds(168, 78, 73, 26);

Label label_2 = new Label(shell, SWT.NONE);
label_2.setText("\u6027\u522B");
label_2.setBounds(72, 129, 35, 20);

Label label_3 = new Label(shell, SWT.NONE);
label_3.setText("\u90E8\u95E8");
label_3.setBounds(72, 167, 35, 20);

Label label_4 = new Label(shell, SWT.NONE);
label_4.setText("\u5DE5\u8D44");
label_4.setBounds(72, 217, 35, 20);

Label label_5 = new Label(shell, SWT.NONE);
label_5.setText("\u51FA\u751F");
label_5.setBounds(72, 262, 35, 20);


text_2 = new Text(shell, SWT.BORDER);
text_2.setBounds(168, 129, 73, 26);

text_3 = new Text(shell, SWT.BORDER);
text_3.setBounds(168, 167, 73, 26);

text_4 = new Text(shell, SWT.BORDER);
text_4.setBounds(168, 211, 73, 26);

text_5 = new Text(shell, SWT.BORDER);
text_5.setBounds(168, 256, 73, 26);

Button button = new Button(shell, SWT.NONE);
button.setBounds(168, 288, 58, 25);
button.setText("\u663E\u793A");
button_2.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
try{ 
    TableColumn column1 = new TableColumn(table, SWT.NONE);  
    column1.setText("姓名"); column1.setWidth(100);  
    TableColumn column2 = new TableColumn(table, SWT.NONE);  
    column2.setText("电话"); column2.setWidth(100);  
    TableColumn column3 = new TableColumn(table, SWT.NONE);  
    column3.setText("性别"); column3.setWidth(100);  
    TableColumn column4 = new TableColumn(table, SWT.NONE);  
    column4.setText("部门"); column4.setWidth(100);  
    TableColumn column5 = new TableColumn(table, SWT.NONE);  
    column5.setText("工资"); column5.setWidth(100);  
    TableColumn column6 = new TableColumn(table, SWT.NONE);  
    column6.setText("出生"); column6.setWidth(100);   
    TableItem item = new TableItem(table, SWT.NONE); 
    item.setText(0,text.getText());     
    item.setText(1,text_1.getText());
    item.setText(2,text_2.getText());
    item.setText(3,text_3.getText());
    item.setText(4,text_4.getText());
    item.setText(5,text_5.getText());
    
    insert demo=new insert();
    PreparedStatement ps=demo.createStatement();
Connection con = null;
String dbURL="jdbc:sqlserver://localhost:1433;"+"DatabaseName=First";
    String userName="sa";
    String userPwd="123456";
    try {
con=DriverManager.getConnection(dbURL,userName,userPwd);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String sqlstr="select * from 员工信息表";
try {
ps=con.prepareStatement(sqlstr,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
    try{
    ResultSet rs=ps.executeQuery();
    rs.moveToInsertRow();
    rs.updateString(1, text.getText());
    rs.updateString(2, text_1.getText());
    rs.updateString(3, text_2.getText());
    rs.updateString(4, text_3.getText());
    rs.updateString(5, text_4.getText());
    rs.updateString(6, text_5.getText());
    rs.insertRow();
    }catch(SQLException e1){
    e1.printStackTrace();
    }
    try{
    if(!con.isClosed()){
    con.close();
    }
    }catch(Exception e3){
    e3.printStackTrace();
    }
    
    text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
     MessageBox box=new MessageBox(shell,0); 
          box.setMessage("添加成功"); 
          box.open();
        }catch(NumberFormatException e1) 
        { 
          MessageBox box=new MessageBox(shell,0); 
          box.setMessage("输入信息无效"); 
          box.open(); 
        }
}
});
button_3.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
int flag=0;
TableItem it[]=table.getItems();
for(int i=0;iif(text.getText().equals(it[i].getText(0))) 
                    { 
                    Device display = null;
it[i].setBackground(new Color(display, SWT.COLOR_DARK_RED, 200, 20));
text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
    flag=1;
     MessageBox box=new MessageBox(shell,0); 
          box.setMessage("查询成功"); 
          box.open();
                    } 
}
if(flag==0){
  MessageBox box=new MessageBox(shell,0); 
          box.setMessage("请输入正确的姓名进行查询"); 
          box.open();
}
}
});
button_4.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
int flag=0;
TableItem it[]=table.getItems();
for(int i=0;iif(text.getText().equals(it[i].getText(0))){
insert demo=new insert();
    PreparedStatement ps=demo.createStatement();
Connection con = null;
String dbURL="jdbc:sqlserver://localhost:1433;"+"DatabaseName=First";
    String userName="sa";
    String userPwd="123456";
    try {
con=DriverManager.getConnection(dbURL,userName,userPwd);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    String s1=text.getText();
String sqlstr="delete from 员工信息表 where 姓名=?";
try {
ps=con.prepareStatement(sqlstr,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    try {
ps.setString(1, s1);
ps.executeUpdate();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    String sqlstr1="select * from 员工信息表";
try {
ps=con.prepareStatement(sqlstr1,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
    try{
    ResultSet rs=ps.executeQuery();
    rs.moveToInsertRow();
    rs.updateString(1, text.getText());
    rs.updateString(2, text_1.getText());
    rs.updateString(3, text_2.getText());
    rs.updateString(4, text_3.getText());
    rs.updateString(5, text_4.getText());
    rs.updateString(6, text_5.getText());
    rs.insertRow();
    }catch(SQLException e1){
    e1.printStackTrace();
    }
    try{
    if(!con.isClosed()){
    con.close();
    }
    }catch(Exception e3){
    e3.printStackTrace();
    }
    it[i].setText(1,text_1.getText());
    it[i].setText(2,text_2.getText());
    it[i].setText(3,text_3.getText());
    it[i].setText(4,text_4.getText());
    it[i].setText(5,text_5.getText());
    text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
    flag=1;
   MessageBox box=new MessageBox(shell,0); 
          box.setMessage("修改成功"); 
          box.open();
                    } 
}
if(flag==0){
MessageBox box=new MessageBox(shell,0); 
          box.setMessage("请输入正确的姓名进行修改"); 
          box.open();
}
    
}
});
button_5.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
TableItem it[]=table.getItems();
int flag=0;
for(int i=0;iif(text.getText().equals(it[i].getText(0))){ 
insert demo=new insert();
    PreparedStatement ps=demo.createStatement();
Connection con = null;
String dbURL="jdbc:sqlserver://localhost:1433;"+"DatabaseName=First";
    String userName="sa";
    String userPwd="123456";
    try {
con=DriverManager.getConnection(dbURL,userName,userPwd);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    String s1=text.getText();
String sqlstr="delete from 员工信息表 where 姓名=?";
try {
ps=con.prepareStatement(sqlstr,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    try {
ps.setString(1, s1);
ps.executeUpdate();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
                table.remove(i);
                text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
                flag=1;
                MessageBox box=new MessageBox(shell,0); 
          box.setMessage("删除成功"); 
          box.open();
            } 
}
if(flag==0){
MessageBox box=new MessageBox(shell,0); 
          box.setMessage("请输入正确的姓名进行删除"); 
          box.open();
}
}
});
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
xianshishell.open();
}
});
}
}

③数据库连接

package xitong;


import java.sql.Connection;


public class mainscreen {
protected Shell shell,xianshishell,shell1;
protected Table table;
private Text text;
private Text text_1;
private Text text_2;
private Text text_3;
private Text text_4;
private Text text_5;


/**
* Launch the application.
* @param args
*/


/**
* Open the window.
* @wbp.parser.entryPoint
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}


/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 370);
shell.setText("主界面");
xianshishell=new Shell();
xianshishell.setSize(450, 300);
xianshishell.setText("显示界面");
Device display = null;
Image image=new Image(display,"H://sublime工作区/pictures/fj.jpg");
shell.setBackgroundImage(image);

table = new Table(xianshishell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
table.setBounds(0, 0, 465, 253);
table.setHeaderVisible(true);
table.setLinesVisible(true);
Button button_2 = new Button(shell, SWT.NONE);
button_2.setBounds(10, 0, 66, 43);
button_2.setText("\u5F55\u5165");

Button button_3 = new Button(shell, SWT.NONE);
button_3.setBounds(116, 3, 66, 37);
button_3.setText("\u67E5\u8BE2");

Button button_4 = new Button(shell, SWT.NONE);
button_4.setBounds(221, 3, 74, 37);
button_4.setText("\u4FEE\u6539");

Button button_5 = new Button(shell, SWT.NONE);
button_5.setBounds(358, 0, 74, 43);
button_5.setText("\u5220\u9664");

Label label = new Label(shell, SWT.NONE);
label.setText("\u59D3\u540D");
label.setBounds(72, 49, 35, 20);

text = new Text(shell, SWT.BORDER);
text.setBounds(168, 46, 74, 26);

Label label_1 = new Label(shell, SWT.NONE);
label_1.setText("\u7535\u8BDD");
label_1.setBounds(72, 86, 35, 20);

text_1 = new Text(shell, SWT.BORDER);
text_1.setBounds(168, 78, 73, 26);

Label label_2 = new Label(shell, SWT.NONE);
label_2.setText("\u6027\u522B");
label_2.setBounds(72, 129, 35, 20);

Label label_3 = new Label(shell, SWT.NONE);
label_3.setText("\u90E8\u95E8");
label_3.setBounds(72, 167, 35, 20);

Label label_4 = new Label(shell, SWT.NONE);
label_4.setText("\u5DE5\u8D44");
label_4.setBounds(72, 217, 35, 20);

Label label_5 = new Label(shell, SWT.NONE);
label_5.setText("\u51FA\u751F");
label_5.setBounds(72, 262, 35, 20);


text_2 = new Text(shell, SWT.BORDER);
text_2.setBounds(168, 129, 73, 26);

text_3 = new Text(shell, SWT.BORDER);
text_3.setBounds(168, 167, 73, 26);

text_4 = new Text(shell, SWT.BORDER);
text_4.setBounds(168, 211, 73, 26);

text_5 = new Text(shell, SWT.BORDER);
text_5.setBounds(168, 256, 73, 26);

Button button = new Button(shell, SWT.NONE);
button.setBounds(168, 288, 58, 25);
button.setText("\u663E\u793A");
button_2.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
try{ 
    TableColumn column1 = new TableColumn(table, SWT.NONE);  
    column1.setText("姓名"); column1.setWidth(100);  
    TableColumn column2 = new TableColumn(table, SWT.NONE);  
    column2.setText("电话"); column2.setWidth(100);  
    TableColumn column3 = new TableColumn(table, SWT.NONE);  
    column3.setText("性别"); column3.setWidth(100);  
    TableColumn column4 = new TableColumn(table, SWT.NONE);  
    column4.setText("部门"); column4.setWidth(100);  
    TableColumn column5 = new TableColumn(table, SWT.NONE);  
    column5.setText("工资"); column5.setWidth(100);  
    TableColumn column6 = new TableColumn(table, SWT.NONE);  
    column6.setText("出生"); column6.setWidth(100);   
    TableItem item = new TableItem(table, SWT.NONE); 
    item.setText(0,text.getText());     
    item.setText(1,text_1.getText());
    item.setText(2,text_2.getText());
    item.setText(3,text_3.getText());
    item.setText(4,text_4.getText());
    item.setText(5,text_5.getText());
    
    insert demo=new insert();
    PreparedStatement ps=demo.createStatement();
Connection con = null;
String dbURL="jdbc:sqlserver://localhost:1433;"+"DatabaseName=First";
    String userName="sa";
    String userPwd="123456";
    try {
con=DriverManager.getConnection(dbURL,userName,userPwd);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String sqlstr="select * from 员工信息表";
try {
ps=con.prepareStatement(sqlstr,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
    try{
    ResultSet rs=ps.executeQuery();
    rs.moveToInsertRow();
    rs.updateString(1, text.getText());
    rs.updateString(2, text_1.getText());
    rs.updateString(3, text_2.getText());
    rs.updateString(4, text_3.getText());
    rs.updateString(5, text_4.getText());
    rs.updateString(6, text_5.getText());
    rs.insertRow();
    }catch(SQLException e1){
    e1.printStackTrace();
    }
    try{
    if(!con.isClosed()){
    con.close();
    }
    }catch(Exception e3){
    e3.printStackTrace();
    }
    
    text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
     MessageBox box=new MessageBox(shell,0); 
          box.setMessage("添加成功"); 
          box.open();
        }catch(NumberFormatException e1) 
        { 
          MessageBox box=new MessageBox(shell,0); 
          box.setMessage("输入信息无效"); 
          box.open(); 
        }
}
});
button_3.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
int flag=0;
TableItem it[]=table.getItems();
for(int i=0;iif(text.getText().equals(it[i].getText(0))) 
                    { 
                    Device display = null;
it[i].setBackground(new Color(display, SWT.COLOR_DARK_RED, 200, 20));
text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
    flag=1;
     MessageBox box=new MessageBox(shell,0); 
          box.setMessage("查询成功"); 
          box.open();
                    } 
}
if(flag==0){
  MessageBox box=new MessageBox(shell,0); 
          box.setMessage("请输入正确的姓名进行查询"); 
          box.open();
}
}
});
button_4.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
int flag=0;
TableItem it[]=table.getItems();
for(int i=0;iif(text.getText().equals(it[i].getText(0))){
insert demo=new insert();
    PreparedStatement ps=demo.createStatement();
Connection con = null;
String dbURL="jdbc:sqlserver://localhost:1433;"+"DatabaseName=First";
    String userName="sa";
    String userPwd="123456";
    try {
con=DriverManager.getConnection(dbURL,userName,userPwd);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    String s1=text.getText();
String sqlstr="delete from 员工信息表 where 姓名=?";
try {
ps=con.prepareStatement(sqlstr,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    try {
ps.setString(1, s1);
ps.executeUpdate();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    String sqlstr1="select * from 员工信息表";
try {
ps=con.prepareStatement(sqlstr1,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
    try{
    ResultSet rs=ps.executeQuery();
    rs.moveToInsertRow();
    rs.updateString(1, text.getText());
    rs.updateString(2, text_1.getText());
    rs.updateString(3, text_2.getText());
    rs.updateString(4, text_3.getText());
    rs.updateString(5, text_4.getText());
    rs.updateString(6, text_5.getText());
    rs.insertRow();
    }catch(SQLException e1){
    e1.printStackTrace();
    }
    try{
    if(!con.isClosed()){
    con.close();
    }
    }catch(Exception e3){
    e3.printStackTrace();
    }
    it[i].setText(1,text_1.getText());
    it[i].setText(2,text_2.getText());
    it[i].setText(3,text_3.getText());
    it[i].setText(4,text_4.getText());
    it[i].setText(5,text_5.getText());
    text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
    flag=1;
   MessageBox box=new MessageBox(shell,0); 
          box.setMessage("修改成功"); 
          box.open();
                    } 
}
if(flag==0){
MessageBox box=new MessageBox(shell,0); 
          box.setMessage("请输入正确的姓名进行修改"); 
          box.open();
}
    
}
});
button_5.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
TableItem it[]=table.getItems();
int flag=0;
for(int i=0;iif(text.getText().equals(it[i].getText(0))){ 
insert demo=new insert();
    PreparedStatement ps=demo.createStatement();
Connection con = null;
String dbURL="jdbc:sqlserver://localhost:1433;"+"DatabaseName=First";
    String userName="sa";
    String userPwd="123456";
    try {
con=DriverManager.getConnection(dbURL,userName,userPwd);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    String s1=text.getText();
String sqlstr="delete from 员工信息表 where 姓名=?";
try {
ps=con.prepareStatement(sqlstr,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
    try {
ps.setString(1, s1);
ps.executeUpdate();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
                table.remove(i);
                text.setText("");
    text_1.setText("");
    text_2.setText("");
    text_3.setText("");
    text_4.setText("");
    text_5.setText("");
                flag=1;
                MessageBox box=new MessageBox(shell,0); 
          box.setMessage("删除成功"); 
          box.open();
            } 
}
if(flag==0){
MessageBox box=new MessageBox(shell,0); 
          box.setMessage("请输入正确的姓名进行删除"); 
          box.open();
}
}
});
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
xianshishell.open();
}
});
}
}

你可能感兴趣的:(java,swt,数据库)