英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论