一段时间以来,我在使用db数据填充ComboBox时遇到了问题,我的代码为组合框:
SQLConnect con = new SQLConnect();
SQLUtility select = new SQLUtility();
ArrayList <String> categories = (ArrayList) select.Select("SELECT category_name FROM gamecategory");
JComboBox comboBox = new JComboBox(categories.toArray());
System.out.println(categories);
在SQLUtility中选择的代码
public class SQLUtility<T> {
private PreparedStatement pst = null;
private ResultSet rs = null;
private SQLConnect database;
public SQLUtility(){
database = SQLConnect.getDatabaseConnectionInstance();
}
@SuppressWarnings("unchecked")
public T Select(String Query) {
try {
pst = database.conn.prepareStatement(Query);
rs = pst.executeQuery();
if(rs.next()) {
return (T) rs.getString(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
我已经检查了一个不同的类,连接是否正常,我能够检索数据,所以它的组合代码是不正确的,有什么想法吗?