这是插入的部分,不知道为什么多选按钮的值总是无法取到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());}这段代码怎样改,改完就给分
展开