java中JTable的问题,求解,大神在哪里

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class a160407 extends JFrame implements ActionListener{
JButton anl1,anl2,anl3,anl4;
JLabel bq;
JTextField wbk;
JPanel mb1,mb2;
JTable bg;
JScrollPane gd;
aaaa aa;
public static void main(String[] args){
a160407 aaa=new a160407();
}
public a160407(){

    anl1=new JButton("查询");
    anl1.addActionListener(this);
    anl1.setActionCommand("chaxun");
    anl2=new JButton("添加");
    anl2.addActionListener(this);
    anl2.setActionCommand("tianjia");
    anl3=new JButton("删除");
    anl3.addActionListener(this);
    anl3.setActionCommand("shanchu");
    anl4=new JButton("修改");
    anl4.addActionListener(this);
    anl4.setActionCommand("xiugai");
    bq=new JLabel("请输入姓名");
    wbk=new JTextField(7);
    mb1=new JPanel();
    mb2=new JPanel();
    aa=new aaaa();  
    bg=new JTable(aa);
    gd=new JScrollPane(bg);

    mb1.setLayout(new FlowLayout());mb1.add(bq);mb1.add(wbk);mb1.add(anl1);

    mb2.setLayout(new FlowLayout());mb2.add(anl2);mb2.add(anl3);mb2.add(anl4);

    this.add(mb1,BorderLayout.NORTH);
    this.add(mb2,BorderLayout.SOUTH);
    this.add(gd);

    this.setResizable(false);
    this.setSize(800,600);
    this.setLocation(300,150);
    this.setTitle("QQ联系人");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);      
}
public void actionPerformed(ActionEvent e){
    if(e.getActionCommand().equals("chaxun")){
        String xingming=this.wbk.getText().trim();
        String sql="select * from QQ where xinmin='"+xingming+"'";
        aa=new aaaa(sql);
        bg.setModel(aa);
    }
    else if(e.getActionCommand().equals("tianjia")){
        tianjia tj=new tianjia(this,"信息添加",true);
        aa=new aaaa();
        bg.setModel(aa);
        System.out.println("fffffffffffffff");
    }
    else if(e.getActionCommand().equals("shanchu")){

        int ii=this.bg.getSelectedRow();
        if(ii==-1){

            JOptionPane.showMessageDialog(this,"请选中要删除的行");
            return;
        }   程序总是运行到下面的这句话出错????????????????????
            String st=(String)aa.getValueAt(ii,0);我发现getValueAt(ii,0)中的0改成1或者其他不是0的数程序就正常了,请好心的大神把我解决一下!
            PreparedStatement ps=null;
            Connection ct=null;
            ResultSet rs=null;
            try{
                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
                 ct=DriverManager.getConnection("jdbc:odbc:SQL Sever","sa","923274995");    
                 ps=ct.prepareStatement("delete  from QQ where xinmin=?");
                 ps.setString(1,st);
                 ps.executeUpdate();
            }catch(Exception e2){}
            finally{
                try {
                    if(rs!=null)
                    {
                        rs.close();
                    }
                    if(ps!=null)
                    {
                        ps.close();
                    }
                    if(ct!=null)
                    {
                        ct.close();
                    }

                } catch (Exception e3){}

            }aa=new aaaa();
            bg.setModel(aa);


    }
    else if(e.getActionCommand().equals("xiugai")){
        int ii=this.bg.getSelectedRow();
        if(ii==-1){ 
            JOptionPane.showMessageDialog(this,"请选中要修改的行");
            return;
        }   
        new xiugai(this,"信息修改",true,aa,ii);

    }
}

}
要解决的问题在上面代码一排问号??????的下面

查看全部
qq_34316891
qq_34316891
2016/04/15 09:55
  • java
  • jtable
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复