Hello,
I have 3 combobox and I want to find them in my table "class" and retrieve the ID.
I am currently having trouble with the following code:
public void retrieveClass(String time,String stage, String teacher){
Connection con = null;
ResultSet rs = null;
java.sql.PreparedStatement st = null;
Properties conProps = new Properties();
conProps.setProperty("user", "root");
conProps.setProperty("password", "root");
try {
con =DriverManager.getConnection ("jdbc:mysql://localhost:3306/database", conProps);
String sql = ("select*from class where Stage = ? and Teacher = ? and Time =? ");
st.setString(1,time);
st.setString(2,stage);
st.setString(3,teacher);
st.executeQuery();
rs = st.getResultSet();
while (rs.next()) {
String teach = rs.getString("ClassID");
txtid.setText(teach);
}
con.commit();
} catch (Exception e) {
}
}
For the button I have this code:
String a = cb5.getSelectedItem().toString();
String b = cb6.getSelectedItem().toString();
String c = cb7.getSelectedItem().toString();
retrieveClass(a,b,c)
I want to retrieve the classID in the textfield. It doesn't do anything.