java 多选按钮的值_如何获取多选按钮的值,并把他插入数据库中,java的问题

这是插入的部分,不知道为什么多选按钮的值总是无法取到b1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){if(((JButton)e.getSource()).getText()...

这是插入的部分,不知道为什么多选按钮的值总是无法取到

b1.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

if(((JButton)e.getSource()).getText()=="注册")

{

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

} catch (ClassNotFoundException e1) {

//TODO Auto-generated catch block

e1.printStackTrace();

}

try {

Connection c=DriverManager.getConnection("jdbc:odbc:card1");

String str = null;

String name=txt1.getText();

String add=liebiao.getSelectedItem().toString();

String jieshao1=jieshao.getText();

String phone1=phone.getText();

Statement s = c.createStatement();

d = (male.isSelected()?"男":"女");

if(check1.isSelected())

str="打球";

if(check2.isSelected())

str+="电动";

if(check3.isSelected())

str+="看书";

if(check4.isSelected())

str+="旅游";

System.out.println(str);

String sql=("insert into car(姓名,地址,性别,爱好,备注,电话) values ('"+name+"','"+add+"','"+d+"','"+str+"','"+jieshao1+"','"+phone1+"')");

s.executeUpdate(sql);

} catch (SQLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

});

我捕捉到了一个异常

try{

if(check1.isSelected())

{str="打球";}

else

str="";

if(check2.isSelected())

{str+="电动";}

if(check3.isSelected())

{str+="看书";}

if(check4.isSelected())

{str+="旅游";}

System.out.println(str);}catch(NullPointerException e1){System.out.println("发生异常的原因为 :"+e1.getMessage());}这段代码怎样改,改完就给分

展开

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值