下面是全部的代码:各位耐心的看看咯!!先谢了
public class DiplayExample extends JFrame {
        String drive="sun.jdbc.odbc.JdbcOdbcDriver";
        String dbURL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生";
        String ur1="jdbc:odbc:student";
        String user="sa";
        String password="zhui007";
        private JTable table; 
        private Connection con; 
        private Statement statement; 
        private ResultSet rs; 
        private Vector rows;
        private Vector columnHeads;
        public DiplayExample()
        {
                super("数据库查询123");
                        try{
                                Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                                con=DriverManager.getConnection(dbURL,user,password);
                                String query = "select sno,sname,sex,native,brithday from student";                                
                                statement = con.createStatement(); 
                                rs= statement.executeQuery( query );
                                
                                columnHeads = new Vector(); 
                                 rows = new Vector(); 
                                ResultSetMetaData rsmd = rs.getMetaData();                                 
                                for ( int i = 1; i <= rsmd.getColumnCount(); ++i ) 
                                        columnHeads.addElement(rsmd.getColumnName( i )); 
                                while(rs.next())
                                {
                                        String []re = new String[rsmd.getColumnCount()];
                                        for(int i=0;i<rsmd.getColumnCount();i++)
                                        {
                                                //rows.addElement(rs.getString(i+1));
                                                re[i]=rs.getString(i+1);
                                        }
                                        rows.addElement(re);
                                }
                                //在表格中显示查询结果
                                        table = new JTable(rows,columnHeads); 
                        }
                        catch (SQLException e){
                                System.out.println(1+e.toString());                                
                        }
                        catch (Exception e1){
                                System.out.println(2+e1.toString());
                        }
                        Container container = getContentPane();
                        container.add(new JScrollPane(table),BorderLayout.CENTER);
                        container.validate();
                        setSize(400,200);
                        setVisible(true);
                        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        }
        /*public String getColumnName(int i)
        {
                return headers[i];
        }*/
        
        
        public static void main(String[] args) {
                new DiplayExample();        }}大家帮忙看看哈!!
错误提示:
java.lang.ClassCastException: [Ljava.lang.String;
我主要是想能自动将数据存入JTable中,可是上面核心语句,在别的地方能用啊,在这里怎么几不行呢?
还有就是rows存不了数据,columnHeads显示的结果也与数据库中存储的不同只显示了部分

解决方案 »

  1.   

    while(rs.next())
                                    {
                                            String []re = new String[rsmd.getColumnCount()];
                                            for(int i=0;i<rsmd.getColumnCount();i++)
                                            {
                                                    //rows.addElement(rs.getString(i+1));
                                                    re[i]=rs.getString(i+1);
                                            }
                                            rows.addElement(re);
                                    }
    这里有错误么?运行到这里就说指针错误
    提示为:
    Invalid operation for the current cursor position
    大家HELP  ME!!!!!!!!!