回 帖 发 新 帖 刷新版面

主题:各位朋友帮帮我,紧急要呀

//SQL代码:

use luo

select * from student
drop table student

create table student
(
ID int primary key,
NAME varchar (15),
SEX varchar(10),
AGE varchar(10)
)

select * from student


insert into student values ('1','aa','n','20')
insert into student values ('2','bb','v','25')
insert into student values ('3','cc','n','21')
insert into student values ('4','dd','v','19')
insert into student values ('5','ee','n','27')
insert into student values ('6','ff','v','32')



//JAVA连接的SQL
package new2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import stuTest.Control;

public class sql {
    public List aa()
    {
        List list =new ArrayList();
        int result = 0;
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
        String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=StuInformation";
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            con = DriverManager.getConnection(url, "sa", "");
            stmt = con.createStatement();
            rs = stmt.executeQuery("select * from student");
            while(rs.next())
            {
            student str = new student();
            str.setID(rs.getInt("ID")); 
            str.setNAME(rs.getString("NAME"));
            str.setSEX(rs.getString("SEX"));
            str.setAGE(rs.getString("AGE"));
            list.add(str);
            
            }
                //System.out.println(result);
            
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println(e.getErrorCode());
            e.printStackTrace();
        }finally{
            try {
                if (stmt != null)
                    stmt.close();
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }    
        }
        return list;
    }

}


//STUDENT 情况
package new2;

public class student {
    private int ID;
    private String NAME;
    private String SEX;
    private String AGE;
    public int getID() {
        return ID;
    }
    public void setID(int ID) {
        this.ID = ID;
    }
    public String getNAME() {
        return NAME;
    }
    public void setNAME(String NAME) {
        this.NAME = NAME;
    }
    public String getSEX() {
        return SEX;
    }
    public void setSEX(String SEX) {
        this.SEX = SEX;
    }
    public String getAGE() {
        return AGE;
    }
    public void setAGE(String AGE) {
        this.AGE = AGE;
    }
    
}



//SWT 文件


package new2;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import new2.student;
public class stu2 extends Shell {

    private Table table_1;
    /**
     * Launch the application
     * @param args
     */
    public static void main(String args[]) {
        try {
            Display display = Display.getDefault();
            stu2 shell = new stu2(display, SWT.SHELL_TRIM);
            shell.open();
            shell.layout();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the shell
     * @param display
     * @param style
     */
    public stu2(Display display, int style) {
        super(display, style);
        createContents();
    }

    /**
     * Create contents of the window
     */
    protected void createContents() {
        setText("SWT Application");
        setSize(500, 375);

        final Menu menu = new Menu(this, SWT.BAR);
        setMenuBar(menu);

        final CTabFolder tabFolder = new CTabFolder(this, SWT.NONE);
        tabFolder.setBounds(0, 0, 492, 321);

        final CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
        tabItem.setText("查找");

        final Composite composite = new Composite(tabFolder, SWT.NONE);
        tabItem.setControl(composite);

        table_1 = new Table(composite, SWT.BORDER);
        table_1.setBounds(0, 106, 488, 194);
        table_1.setLinesVisible(true);
        table_1.setHeaderVisible(true);

        final TableColumn col = new TableColumn(table_1, SWT.NONE);
        col.setText("学号");

        final TableColumn col_2 = new TableColumn(table_1, SWT.NONE);
        col_2.setText("姓名");

        final TableColumn col_3 = new TableColumn(table_1, SWT.NONE);
        col_3.setText("性别");

        final TableColumn col_4 = new TableColumn(table_1, SWT.NONE);
        col_4.setText("年龄");

        final Button button = new Button(composite, SWT.NONE);
        button.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                table_1.removeAll();
                List lis = new ArrayList();
                sql sq = new sql();
                lis = sq.aa();
                //???????????
                ??????????
                //这个地方怎样写,我想当点击按钮的时候table显示SQL的信息
                //?????????
                //???????
                
            }
            
        });
        button.setText("确定");
        button.setBounds(213, 45, 48, 22);

        final Label label = new Label(composite, SWT.NONE);
        label.setText("完全查找 ");
        label.setBounds(134, 50, 54, 12);
        //
    }

    @Override
    protected void checkSubclass() {
        // Disable the check that prevents subclassing of SWT components
    }

}

回复列表 (共1个回复)

沙发

SWT 文件 没有写完。。。。。。。。。。。
请各位好友帮我补充,谢谢

我来回复

您尚未登录,请登录后再回复。点此登录或注册