如题。。

解决方案 »

  1.   

    String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
    String url="jdbc:odbc:db1";
    Class.forName(driverName).newInstance();
    Connection conn=DriverManager.getConnection(url,"","");
    ....
    conn.close();
      

  2.   

    package com.huawei.netcb.word;import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;public class SystemOS extends JFrame implements ActionListener {
    JPanel pnlMain;
    JTextField txtfile;
    JButton btnSelect;
    JFileChooser fc = new JFileChooser();
    JCheckBox cb = null;
    String filepath = ""; public SystemOS() {
    pnlMain = new JPanel();
    this.getContentPane().add(pnlMain);
    txtfile = new JTextField(12);
    btnSelect = new JButton("选择保存文件路径");
    this.setSize(300, 400);
    int i = 0;
    for (; i < 4; i++) {
    JCheckBox cb= new JCheckBox();
    cb.setText("132");
    } btnSelect.addActionListener(this);
    pnlMain.add(cb, "Center");
    pnlMain.add(txtfile, "Center");
    pnlMain.add(btnSelect, "Center"); this.setResizable(false);
    this.setVisible(true);
    pnlMain.setLayout(new BorderLayout());
    } public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnSelect) {
    /*
     * 这是尤为重要的。因为JFileChooser默认的是选择文件,而需要选目录。 故要将DIRECTORIES_ONLY装入模型
     * 另外,若选择文件,则无需此句
     */
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int intRetVal = fc.showOpenDialog(this);
    if (intRetVal == JFileChooser.APPROVE_OPTION) {
    txtfile.setText(fc.getSelectedFile().getPath());
    filepath = txtfile.getText();
    }
    }
    } public static void main(String[] args) {
    JFrame f = new SystemOS(); }
    }