首先關閉它,這裏是我的代碼:獲取ResultSet是封閉的例外,但我沒有在代碼
public void getGK()
{
add(p4);
setSize(1200,700);
setLocation(30,17);
p4.setVisible(true);
p4.setLayout(null);
final CheckboxGroup cg=new CheckboxGroup();
final JLabel q=new JLabel();
final JButton b6=new JButton("Submit");
b6.setBounds(150,250,80,50);
q.setBounds(40,40,1000,50);
q.setForeground(Color.RED);
q.setFont(new Font("Castellar",Font.BOLD,15));
p4.add(l1);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
co=DriverManager.getConnection("jdbc:odbc:Quizdata","","");
st=co.createStatement();
final String s2="SELECT * FROM GK Where ID="+lx[n];
re=st.executeQuery(s2);
q.setText(re.getString(2));
p4.add(q);
final Checkbox c5=new Checkbox();
final Checkbox c1=new Checkbox(re.getString(3),cg,false);
final Checkbox c2=new Checkbox(re.getString(4),cg,false);
final Checkbox c3=new Checkbox(re.getString(5),cg,false);
final Checkbox c4=new Checkbox(re.getString(6),cg,false);
c1.setBounds(40,100,400,20);
c2.setBounds(40,130,400,20);
c3.setBounds(40,160,400,20);
c4.setBounds(40,190,400,20);
p4.add(c1);
p4.add(c2);
p4.add(c3);
p4.add(c4);
p4.add(b6);
re.;
final String s3=re.getString("Answer");
b6.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
if(s3.equals(cg.getSelectedCheckbox().getLabel()))
{
System.out.println("THis is correct bwoy " +cg.getSelectedCheckbox().getLabel());
n++;
score++;
remove(p4);
p4.removeAll();
if(n<10)
{
getGK();
}
else
{
System.out.println("Thanks for playing");
}
}
else
{
System.out.println("You are wrong");
}
}
});
co.close();
st.close();
}
catch(Exception z)
{
JOptionPane.showMessageDialog(null,z);
}
}
正如你可以看到我並沒有關閉ResultSet重,但我仍然得到Resulset關閉例外。 如何解決它。代碼還有一個問題,當面板刪除所有組件並再次添加新組件時,複選框可以正常工作,但標籤不會更改,我必須將框架大小化以更改它。 PLZ儘快解決這個問題。
P.S.-這裏的LX [],n是通過這個代碼來:
ArrayList<Integer> num=new ArrayList<Integer>();
for(int it=1;it<=10;it++)
{ num.add(it);}
for(int jt=0;jt<lx.length;++jt)
{
int i=(int)(Math.random()*num.size());
lx[jt]=num.get(i);
num.remove(i);
}
你可以請縮進你的代碼正確。這是不可讀的。 –
@Himanshu你可以請發佈完整的錯誤堆棧跟蹤? – Rohan