我已经做了电影票预订的代码,现在我在
JList
是的。
如何在中添加数据
列表框
是吗?
这是密码…
JList listTime = new JList();
listTime.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listTime.setFont(new Font("Times New Roman", Font.PLAIN, 25));
listTime.setBounds(329, 311, 200, 50);
frame.getContentPane().add(listTime);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suhel","root","Suhel786");
Statement stmt = con.createStatement();
String sql="select distinct time from tbmovie where movie='"+select_mov+"'";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
listTime.add(rs.getString("time"));//here is the Error
}
}
catch(Exception e1){
System.out.print(e1);
}
我已从数据库中检索到数据-只需要在列表中添加数据。