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);
}
这样您就可以看到异常。
关于java - JcomboBox与Sqlite数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31806772/