青春常驻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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)