我正在使用以下代码从数据库中检索数据,但我不知道如何显示它JList
Class.forName("oracle.jdbc.driver.OracleDriver");
Statement stmt = null;
ResultSet rs;
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/SPL","root","PWD");
stmt=(Statement) conn.createStatement();
rs=stmt.executeQuery(query);
while (rs.next())
{
String stadium = rs.getString("Stadium");
String city = rs.getString("City");
}
但我想在JList
. 你们能告诉我该怎么做吗?
我正在使用以下代码,但它没有在我的框架上显示任何内容,你能告诉我哪里错了吗?谢谢
String query="SELECT * FROM Location";
DefaultListModel model=new DefaultListModel();
DefaultListModel model1=new DefaultListModel();
try
{ Class.forName("oracle.jdbc.driver.OracleDriver");
Statement stmt = null;
ResultSet rs;
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/SPL","root","PWD");
stmt=(Statement) conn.createStatement();
rs=stmt.executeQuery(query);
while (rs.next())
{
String stadium = rs.getString("Stadium");
String city = rs.getString("City");
model.addElement(stadium);
model1.addElement(city);
}
JList list=new JList(model);
JList list1=new JList(model1);
f8.add(jpa1); //f8=frame name,jpa1=panel name
jpa1.add(list); list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
list.setVisibleRowCount(1);
JScrollPane listScroller = new JScrollPane(list);
}
catch(SQLException e)
{
System.out.println("Message : " + e.getMessage());
}