我想将数据库中的数据显示到 JList 中。但是它给出的错误是
non static variable list cannot be referenced from a static context"
at line "list.setModel(listModel)".
我应该怎么办?
Connection con=DriverManager.getConnection("jdbc:odbc:Records");
Statement st=con.createStatement();
DefaultListModel listModel=new DefaultListModel();
ResultSet rs=st.executeQuery("Select * from User_table1");
while(rs.next()) {
String name=rs.getString("Filename");
listModel.addElement(name);
System.out.println(name);
}
list.setModel(listModel);
rs.close();
st.close();