JcomboBox与Sqlite数据库

时间:2015-08-04 10:24:50

标签: java mysql sqlite jdbc jcombobox

I have never ever seen such an error..

当我按下按钮时,我只是试图从数据库中调用数据。这是我的代码

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);

            }

然后,当我按下刷新时,这件事就会继续发生。

1 个答案:

答案 0 :(得分:0)

要证明Florent的评论,请更改

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

        }

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

        }

所以你可以看到异常。