Good morning, I'm trying to populate comboBox from database. its my first time and i'm messing it all up, i cant find a good tutorial about it online.
please help structure the code.Thanks you for taking time to read this.
<code>private void jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
Statement stst = (Statement)conn.createStatement();
String sql = "SELECT CodeId FROM Courses";
int index = 0;
ResultSet rs = stst.executeQuery(sql);
while(rs.next()){
// items[index]= rs.getString("CodeId");
// jComboBox.addItem(rs.getString("CodeId"));
//clears the contents of the combo box
Course course = new Course();
course.getCodeId();
jComboBox.removeAllItems();
jComboBox.insertItemAt("Course", 0);
jComboBox.setSelectedIndex(0);
// jComboBox.addItem(rs.getString(""));
for (int i = 1; i < course; i++){
jComboBox.insertItemAt(getCodeId[i], i);
}
}
rset.close();
stst.close();
}catch (SQLException e){
e.printStackTrace();
}
} </code>