java ResultSet,使用MAX sql函数 [英] java ResultSet, using MAX sql function
本文介绍了java ResultSet,使用MAX sql函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,这是我想要的,我连接到数据库并检索UniqueId列的最大元素,并将其分配给名为maxID的整数变量,这是我的方法:
int maxID = 0;
Statement s2 = con.createStatement();
s2.execute("SELECT MAX(UniqueId) FROM MyTable");
ResultSet rs2 = s2.getResultSet(); //
while ( rs2.next() ){
maxID = rs2.getInt(0);
}
解决这个问题的一种体面的方式,感觉是通过在while循环中使用"rs2.next()"来实现的.
谢谢
解决方案
if (rs2.next()) {
maxID = rs2.getInt(1);
}
Hello here is what I want, I connect to a DB and retrieve the biggest element of the UniqueId column, and assign it to an integer variable named maxID, here is my approach:
int maxID = 0;
Statement s2 = con.createStatement();
s2.execute("SELECT MAX(UniqueId) FROM MyTable");
ResultSet rs2 = s2.getResultSet(); //
while ( rs2.next() ){
maxID = rs2.getInt(0);
}
What would be a decent way of solving this, it feels like a very crude way by using "rs2.next()" while loop.
Thanks
解决方案
if (rs2.next()) {
maxID = rs2.getInt(1);
}
这篇关于java ResultSet,使用MAX sql函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文