buat tampilan seperti dibawah :
disini kita akan menampilkan data nama barang pada JList 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(){
DefaultListModel lstmodel = new DefaultListModel<>();
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()){
lstmodel.addElement(rs.getString(2).toString());
}
rs.close();
st.close();
p_connect.close();
lstbarang.setModel(lstmodel);
}catch(Exception e) {
}
}
hasil :