这是发生错误的类
public class Drinks extends JFrame {
private JPanel contentPane;
private JButton button;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Drinks frame = new Drinks();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Drinks() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 401, 401);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JList list = new JList();
list.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent arg0) {
}
private Component StringtoInt(String string) {
// TODO Auto-generated method stub
return null;
}
});
list.setBorder(new CompoundBorder(new MatteBorder(3, 3, 3, 3, (Color) new Color(0, 0, 0)), null));
list.setFont(new Font("Tahoma", Font.PLAIN, 14));
JLabel lblDrink = new JLabel("Drink");
lblDrink.setFont(new Font("Tahoma", Font.PLAIN, 18));
JLabel lblIngredients = new JLabel("Ingredients");
lblIngredients.setFont(new Font("Tahoma", Font.PLAIN, 18));
button = new JButton("Back");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainMenu frame = new MainMenu();
frame.setVisible(true);
dispose();
}
});
JTextPane textPane = new JTextPane();
textPane.setBorder(new LineBorder(new Color(0, 0, 0), 3));
这是我相信问题的地方,你可以看到没有 现有的密切陈述
JButton btnLoad = new JButton("Load");
btnLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try{
Connection connDrink = Connections.sqlConn();
int countDrinks = Connections.count();
System.out.println(countDrinks);
for (int j = 0; j < countDrinks; j++) {
String dk = "select DrinkID, Drink from Drinks where DrinkID = " + j + ";";
PreparedStatement pSt = connDrink.prepareStatement(dk);
ResultSet rS = pSt.executeQuery();
System.out.println(rS.getString(2));
int oi = Integer.parseInt(rS.getString(1).toString());
`//`list.add(rS.getString(2).toString(), null);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e.getClass().getName() + ": " + e.getMessage());
}
}
});
始终给出java.sql.SQLException:结果集已关闭,我无法找到结果集关闭的位置或是否有其他错误
答案 0 :(得分:1)
我没有足够的评论意见,所以我会在这里回答。
你应该试试
if(rS.first())// move the cursor to the first row, true if there's a row, false otherwise
System.out.println(rS.getString(2));