我有兩個JComboboxes A和B,所以如果我選擇任何項目形式A,那麼與A中選擇的項目相關的值應填入JCombobox B.我試過這個,但得到一個錯誤:填充JCombobox值取決於另一個JCombobox
java.lang.ArrayIndexOutOfBoundsException: 0
在pst.setString(1, client.getSelectedItem().toString());
try
{
String query="select `User_Name` from Client where `Client_Name`='?' ";
PreparedStatement pst=conn.prepareStatement(query);
pst.setString(1, client.getSelectedItem().toString());
ResultSet rs=pst.executeQuery();
user.addItem("--Select--");
while(rs.next())
{
user.addItem(rs.getString("User_Name"));
}
// return;
System.out.println(query);
}
catch(Exception g)
{
g.printStackTrace();
}
你會得到什麼錯誤?在什麼情況下執行這個代碼?在聽衆? –
是先生,在itemListener ...得到錯誤ArrayIndexOutOfBoundsException在行pst.setString(1,client.getSelectedItem()。toString()); ....但如果我傳遞硬編碼字符串,而不是'?'所以它的工作正常....但它不是目標 – Vsal
@ hunter,在這裏我從數據庫中獲取客戶端名稱...因此,從組合框中選擇此客戶端名稱給'?'並將價值傳遞給此?如果我設置0,那麼錯誤是java.lang.ArrayIndexOutOfBoundsException:-1 – Vsal