JDBC从访问表中选择最大值

编程入门 行业动态 更新时间:2024-10-27 04:31:23
本文介绍了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从访问表中选择最大值

本文发布于:2023-10-16 20:26:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498648.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最大值   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!