如何将MYsql数据库中的记录插入到jScrollPane中

时间:2017-03-06 15:57:10

标签: java mysql

您好我想在jscrollpane中的jList中添加记录列表,请各位帮帮我

班级Values

public static JList<String> indicesJList;


indicesJList = new JList<String>(); 
        indicesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        indicesJList.setLayoutOrientation(JList.VERTICAL);
        indicesJList.setVisibleRowCount(-1);    

listScroller = new JScrollPane(**indicesJList**,ScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

班级Database

public static void GetUSMarket() throws SQLException {
java.sql.Connection con = DriverManager.getConnection(url + dbName, userName, password);

PreparedStatement ps = con.prepareStatement("SELECT Company FROM tbindices WHERE Continent = ('North America')");
ResultSet result = ps.executeQuery();


if (result != null) {
    while (result.next())

    {
        Values.indicesJList.add("company"); // here I have an error 
    }

}

ps.close();
con.close();
}

}

0 个答案:

没有答案