c语言system cmb,one combobox cannot add all it's items into ms access database

问题

> [i want to add all combobox item in msaccess database]

i want to do this

i want to add every items of one combobox into msaccess database for e.g. i want

to do that my combo has 4 fields one,two,three,four and database has four fiels route1,route2,route3,route4...i want to set as route1=one, route2= two....etc.

and if i added 2 items in combobox then remaining two doesnt remainig blank.

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);

}

}

[i got error as]

java.lang.ArrayIndexOutOfBoundsException: 3 >= 2

来源:https://stackoverflow.com/questions/15201220/one-combobox-cannot-add-all-its-items-into-ms-access-database

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值