青春常驻1 2021-12-19 17:25 采纳率: 100%
浏览 210
已结题

The method getstuID() in the type people is not applicable for the arguments (String)

getstuID()出现了标题这个错误

我的 people 类

public class people {
    private String stuID;
    private String name;
    private int score;
    
    people(){}
    
    public String getstuID() {
        return this.stuID;
    }
    public void setstuID(String id) {
          this.stuID = id;
    }
    
    public String getname() {
        return this.name;
    }
    
    public void setname(String name) {
          this.name = name;
    }
    
    public int getscore() {
        return this.score;
    }
    
    public void setscore(int score) {
        this.score = score;
    }

    

    
}

下面的是我出错的那个类

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class idea {
    private static idea instance = new idea();
    public static idea getInstance() {
        return instance;
    }
    
    private idea() {}
    public boolean saveStudent(people stu) {
        boolean result = false;
        Connection conn = null;
        
        try {
            conn = JdbcAccess.getConnection();
            String sqlInset = "insert into CJGL.student(stuID, Name, score) values(?, ?, ?)";
            PreparedStatement stmt = conn.prepareStatement(sqlInset);
            
            stmt.setString(1, stu.getstuID());
            stmt.setString(2, stu.getname());
            stmt.setInt(3, stu.getscore());
            int i = stmt.executeUpdate();
            if(i==1) {
                result = true;
            }
        }catch(SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                conn.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }
        }
        return result;
        
    }
    
    public List<people> selectPeople(){
        List<people> peoList = new ArrayList<people>();
        Connection conn = null;
        try {
        conn = JdbcAccess.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from CJGL.student");
        while(rs.next()) {
            people stu = new people();
            stmt.setstuID(1, stu.getstuID("ID"));
            stmt.setname(2, stu.getname("name"));
            stmt.setscore(3, stu.getscore("score"));
            peoList.add(stu);
            
        }
    }catch(Exception e) {
         e.printStackTrace();
    }finally {
        try {
            conn.close();
        }catch(SQLException e) {
             e.printStackTrace();
        }
    }
        return peoList;
}
}

img

我的解答思路和尝试过的方法

我试过直接点那个

img


然后错误就去到setstuID()那边了

楼主是初学者,这该咋整

  • 写回答

2条回答 默认 最新

  • 关注

    代码写反了,修改如下:

    while(rs.next()) {
                people stu = new people();
                stu.setstuID(rs.getString("ID"));
                stu.setname(rs.getString("name"));
                stu.setscore(rs.getInt("score"));
                peoList.add(stu);
                
            }
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月27日
  • 已采纳回答 12月19日
  • 创建了问题 12月19日

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助