账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    The method next() is undefined for the type Object ?
    60
    0
    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("学号");
            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();
                
            //标记A,next下划线报错,The method getString(int) is undefined for the type Object            
            //标记B,getString下划线报错,连续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();
    //标记C, .close报错,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);
            
        }
    
    }

    无法上传图片,
    标记A
    标记B
    标记C,
    跟着教程码的,教材没报错,很久了没解决,
    谢谢,

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 人丑任性 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部