buat tampilan seperti dibawah :
disini kita akan menampilkan data nama barang pada JComboBox dengan menggunakan JButton Event
Code :
Connection p_connect;
Statement st;
ResultSet rs;
private void btnlistActionPerformed(java.awt.event.ActionEvent evt) {
p_tampil();
}
private void p_tampil(){
cbobarang.removeAllItems();
String sql = "select * from barang";
try{
Class.forName("org.sqlite.JDBC");
String url = "jdbc:sqlite:d://tokoku.db";
p_connect = DriverManager.getConnection(url);
st = p_connect.createStatement();
rs = st.executeQuery(sql);
while(rs.next()){
cbobarang.addItem(rs.getString(2).toString());
}
rs.close();
st.close();
p_connect.close();
}catch(Exception e) {
}
}
hasil :