データベース内の本またはユーザーを検索するためのこのコードは、ユーザーを検索する場合は問題ありませんが、存在しない本を検索する場合は、次のエラーが表示されます。
エラー:結果セットの終了後
if(RB1.isSelected()==true)
{
Statement stmt = (Statement)conn.createStatement();
String SQL1 = "select * from usernames";
ResultSet rs1 = stmt.executeQuery(SQL1);
String ID ="";
while(rs1.next())
{
ID = rs1.getString("UserID");
if(UIorBItf.getText().compareTo(ID) == 0)
{
JOptionPane.showMessageDialog(null,rs1.getString("Full_Name") +
" is available","Query result",JOptionPane.INFORMATION_MESSAGE);
break;
}
}
if(UIorBItf.getText().compareTo(ID) != 0)
{
JOptionPane.showMessageDialog(null, UIorBItf.getText() +" is
not available","Query result",JOptionPane.INFORMATION_MESSAGE);
}
}
if(RB2.isSelected()==true)
{
//JOptionPane.showMessageDialog(null, UIorBItf.getText() +" Now
//You are inside Book search","Query result",JOptionPane.INFORMATION_MESSAGE);
Statement stmt2= (Statement)conn.createStatement();
String SQL2 = "select * from books";
ResultSet rs2 = stmt2.executeQuery(SQL2);
String ID ="";
while(rs2.next())
{
ID = rs2.getString("BookID");
if(ID.compareTo(UIorBItf.getText()) ==0)
{
JOptionPane.showMessageDialog(null,rs2.getString("Book_Name") +
" is available","Query result",JOptionPane.INFORMATION_MESSAGE);
break;
}
}
if(UIorBItf.getText().compareTo(ID)!=0)
{
JOptionPane.showMessageDialog(null,rs2.getString("Book_Name") +
" is not available","Query result",JOptionPane.INFORMATION_MESSAGE);
}
}
}catch(Exception e)
{
System.out.println("Error: " + e.getMessage());
}