填充组合框抛出java.lang.String无法强制转换为java.util.ArrayList

时间:2014-03-18 13:39:15

标签: sql arrays database combobox

一段时间以来,我在使用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;
}

我已经检查了一个不同的类,连接是否正常,我能够检索数据,所以它的组合代码是不正确的,有什么想法吗?

0 个答案:

没有答案