> [i want to add all combobox item in msaccess database]
私はこれをしたいです.1つのコンボボックスのすべてのアイテムをmsaccessデータベースに追加したい.例えば
、私のコンボには4つのフィールド1,2,3,4があり、データベースには4つのフィールドroute1,route2,route3,route4.. .i は route1=one、route2= two などに設定したい。コンボボックスに2つのアイテムを追加すると、残りの2つは空白のままになりません。
if(e.getSource()==btn_save)
{
try{
Connection con;
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:dsnproj","","");
Statement s1 = con.createStatement();
String q1="insert dest,route1,route2,route3,route4 into trans_dest values(
'"+cmb_dest.getSelectedItem()+"',
'"+cmb_route.getItem(1)+"',
'"+cmb_route.getItem(2)+"',
'"+cmb_route.getItem(3)+"',
'"+cmb_route.getItem(4)+"')";
s1.execute(q1);
}
catch(Exception ae)
{
System.out.println(ae);
}
}
}
public void focusLost(FocusEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
if(e.getSource()==txt_route)
{
// transport t=new transport();
JFrame frame = new JFrame();
String[] options = {"Yes", "No"};
int n = JOptionPane.showOptionDialog(frame,
"Do you want to add more routes?",
"",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //do not use a custom Icon
options, //the titles of buttons
null); // disabled the ENTER Key
System.out.println(n);
if (n == JOptionPane.YES_OPTION) {
cmb_route.add(txt_route.getText());
txt_route.setText("");
} else {
cmb_route.add(txt_route.getText());
txt_route.setText("");
}
}
int i=cmb_route.getItemCount();
if(i==4)
{
s1=cmb_route.getItem(0);
s2=cmb_route.getItem(1);
s3=cmb_route.getItem(2);
s4=cmb_route.getItem(3);
cmb_route.insert(s1, 0);
cmb_route.insert(s2, 1);
cmb_route.insert(s3, 2);
cmb_route.insert(s4, 3);
}
else
if(cmb_route.getItemCount()==3)
{
s1=cmb_route.getItem(0);
s2=cmb_route.getItem(1);
s3=cmb_route.getItem(2);
cmb_route.insert(s1, 0);
cmb_route.insert(s2, 1);
cmb_route.insert(s3, 2);
cmb_route.insert("", 3);
}
else
if(cmb_route.getItemCount()==2)
{
s1=cmb_route.getItem(0);
s2=cmb_route.getItem(1);
cmb_route.insert(s1, 0);
cmb_route.insert(s2, 1);
cmb_route.insert("", 2);
cmb_route.insert("", 3);
}
else
if(cmb_route.getItemCount()==1)
{
s1=cmb_route.getItem(0);
cmb_route.insert(s1, 0);
cmb_route.insert("", 1);
cmb_route.insert("", 2);
cmb_route.insert("", 3);
}
}
[エラーが発生しました] java.lang.ArrayIndexOutOfBoundsException: 3 >= 2