JDBC从访问表中选择最大值 [英] JDBC selecting the Max value from an Access table
本文介绍了JDBC从访问表中选择最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使我的表中存在该列,只要运行以下代码,我都会收到错误消息找不到列".我正在使用访问数据库,请寻求帮助
I got error "Column not found" any time i run the following code even though the column exist in my table. Am using access database, Appealing for help please
public class Trial1 {
public static void main (String[]args){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:SENSOR";
String user = "";
String pass = "";
Connection con = DriverManager.getConnection(url,user,pass);
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); //stmt代表資料庫連接成功
ResultSet rs = stmt.executeQuery("select MAX(LevelNum) from NList");
if (rs.next()){
int w = rs.getInt("LevelNum");
int x= 3;
double i = Math.pow(2, (w-x))-1;
System.out.printf("i is %f",i);}
stmt.close();
con.close();
}catch(Exception e)
{
System.out.println("Error" + e);
}
}
}
推荐答案
假设错误是在获取结果时而不是在执行查询时发生的,则可能需要这样的东西
Assuming the error is when you get the result rather than when you execute the query, you probably need something like this instead
// ...
ResultSet rs = stmt.executeQuery("select MAX(LevelNum) as maxLevel from NList");
if (rs.next())
{
int w = rs.getInt("maxLevel");
// ... etc.
}
这篇关于JDBC从访问表中选择最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文