这是否正确,当我想使用Java Netbeans从数据库MySQL中查看某些最大值时?

huangapple go评论150阅读模式
英文:

is it right when i want to view some maximum value from database MySql using Java Netbeans

问题

public Double maksimal1() {
    double m1 = 0;
    query = "SELECT MAX(`K1`) FROM penilaian ";
    status = koneksi.eksekusiQuery(query, true);
    if(status){
        rsMatriks = koneksi.getRs();
        try{
            rsMatriks.next();
            m1 = rsMatriks.getDouble("K1");
            rsMatriks.close();
        }catch(SQLException ex){
            return null;
        }
    }
    return m1;
}
英文:
public Double maksimal1() {
    double m1 = 0;
    query = "SELECT MAX(`K1`) FROM penilaian ";
    status = koneksi.eksekusiQuery(query, true);
    if(status){
        rsMatriks = koneksi.getRs();
        try{
            rsMatriks.next();
            m1= rsMatriks.getDouble("K1");
            rsMatriks.close();
        }catch(SQLException ex){
            return null;
        }
    }
    return m1;
}

答案1

得分: 1

你的查询返回1列,如果你想通过名称访问它,应该给它取个别名为 K1

query = "SELECT MAX(`K1`) AS K1 FROM penilaian";

或者,如果你想通过索引访问它,索引为 1,因为它是唯一的一列:

m1 = rsMatriks.getDouble(1);
英文:

Your query returns 1 column which you should alias as K1 if you want to access it by name:

query = "SELECT MAX(`K1`) AS K1 FROM penilaian";

or if you want to access it by its index which is 1 since it is the only column:

m1 = rsMatriks.getDouble(1);

huangapple
  • 本文由 发表于 2020年10月26日 19:57:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/64536683.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定