0
我有這個枚舉類,一個Question類,一個存儲問題,選項,類別等的數據庫。 問題類有它的getter()和setter() 我的問題是我如何可以從數據庫中存儲字符串類型數據的類型類型? rs.getString(「Cateogory」)返回一個字符串,但我想將此字符串存儲在類別類型obj中。我怎麼能這樣做?在java中的Enum對象中存儲一個字符串
public enum Category {
Geography,History,GK,Science;
}
public class Question {
private int srno;
private String question;
private String option1;
private String option2;
private String option3;
private String option4;
private String correctAns;
private Category Category;
private Complexity complexity;
public Question() {
}
Class X{
ResultSet rs=null;
Statement stmt=null;
List<Question> quesList=new ArrayList<Question>();
Question q=new Question();
Category c=null;
// some code here .....
while(rs.next())
{
q.setQuestion(rs.getString("Question"));
q.setOption1(rs.getString("optionA"));
q.setOption2(rs.getString("optionB"));
q.setOption3(rs.getString("optionC"));
q.setOption4(rs.getString("OptionD"));
// But how do i store a Category type?
quesList.add(q);
}
}
製作'Category'一個'Class',而不是一個'Enum' ... –
爲什麼呢?數據庫中的類別字符串是否與枚舉中的類別常量完全相同? – RealSkeptic