-
Urgent help
How to use DefaultComboBoxModel by connecting to database(Microsoft Access).....to retrieve studentID(i have no problem in connecting but i need to know how to use this method)
//DefaultComboBoxModel model=new DefaulltComboBoxModel();
//JComboBox jcboStud=new JComboBox(model);
then i don't know how to add the value into the combobox(Student Id)
please help me becoz i m going to have practical exam very soon...
advance thanks.....
-
What you have tried so far?
Did you try addItem()?
-
Add Item
in the initialize() method i didn't add addItem but i declare addElement like u see at the bottom
private void initializeDB(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conTARCollegeDB = DriverManager.getConnection("jdbc:odbc:TARCollegeD S");
stmtInitialize = conTARCollegeDB.createStatement();
stmtSearch = conTARCollegeDB.createStatement();
stmtInsert = conTARCollegeDB.createStatement();
stmtUpdate = conTARCollegeDB.createStatement();
stmtDelete = conTARCollegeDB.createStatement();
rsStudent = stmtInitialize.executeQuery("SELECT StudentID FROM Student;");
while (rsStudent.next()){
String studentID = rsStudent.getString(1);
dcbomStudentID.addElement((Object)studentID);
}
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(null, "Error in connecting to database...");
}
}
but i can only retrieve data(Student ID) for combobox...how to retrieve from the other column such as Student Name,CourseID tat match the student ID?thx
-
You have to use the correct query to retrieve data you want.