鍍金池/ 問(wèn)答/Java/ The method next() is undefined for the t

The method next() is undefined for the type Object ?

package com.test1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class Test2 extends JFrame{

    Vector rowData,columnNames;
    JTable jt = null;    
    JScrollPane jsp = null;
    
    PreparedStatement ps = null;
    Connection ct=null;
    ResultSet rs=null;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }
    public Test2(Object rs, Object ps, Object ct){
        columnNames = new Vector();
        
        columnNames.add("學(xué)號(hào)");
        columnNames.add("名字");
        columnNames.add("性別");
        columnNames.add("年齡");
        columnNames.add("籍貫");
        columnNames.add("系別");
        
        rowData = new Vector();
         try {
            Class.forName("com.mysql.jdbc.Driver");
            ct = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3066/"
                        + "book?CharacterEncoding=gbk","root","root");
            ps = ((Connection) ct).prepareStatement("select * from stu");
            rs = ((PreparedStatement) ps).executeQuery();
            
        //標(biāo)記A,next下劃線報(bào)錯(cuò),The method getString(int) is undefined for the type Object            
        //標(biāo)記B,getString下劃線報(bào)錯(cuò),連續(xù)4行,The method getString(int) is undefined for the type Object    
        while(rs.next()){
                Vector hang = new Vector();
                hang.add( rs.getString(1));
                hang.add(rs.getString(2));
                hang.add(rs.getString(3));
                hang.add(rs.getInt(4));
                hang.add(rs.getString(5));
                hang.add( rs.getString(6));
                
                rowData.add(hang);
            }
            
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
//標(biāo)記C, .close報(bào)錯(cuò),The method close() is undefined for the type Object
        
}finally{
            try{
                if(rs!=null ) rs.close();
                if(ps!=null)  ps.close();
                if(ct!=null)   ct.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        
        jt = new JTable(rowData,columnNames);
        jsp = new JScrollPane(jt);
        
        this.add(jsp);
        this.setSize(400, 350);
        
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        
    }

}

無(wú)法上傳圖片,
標(biāo)記A
標(biāo)記B
標(biāo)記C,
跟著教程碼的,教材沒(méi)報(bào)錯(cuò),很久了沒(méi)解決,
謝謝,

回答
編輯回答
神曲

public Test2(Object rs, Object ps, Object ct)
替換為
public Test2(ResultSet rs, PreparedStatement ps, Connection ct)

2017年1月8日 09:08