带有 Sqlite 数据库的 JcomboBox

JcomboBox with Sqlite Database

我只是想在按下按钮时从数据库中调用数据。这是我的代码

JButton btnRefresh = new JButton("Refresh");
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Connection conni = null;
            ResultSet rs=null;
            PreparedStatement pst=null;
            try{
                Class.forName("org.sqlite.JDBC");
                conni  = DriverManager.getConnection("jdbc:sqlite://C://Users//Asus//Dropbox//TireShop.sqlite");
                String sql="select * from Namet";


                pst=conni.prepareStatement(sql);
                rs=pst.executeQuery();
                while(rs.next()){
                    String name = rs.getString("Namet");
                    comboBox.addItem(name);

                }

            }catch(Exception i){
                JOptionPane.showMessageDialog(null, e);

            }

然后当我按刷新时这个东西一直出现。

要演示 Florent 的评论,请更改

        }catch(Exception i){
            JOptionPane.showMessageDialog(null, e);

        }

        }catch(Exception i){
            JOptionPane.showMessageDialog(null, i);

        }

所以你可以看到异常。