请教一下用SQL语句取数到一个变量上的代码.

Joey 2007-09-08 09:10:15
我想从SQL数据库的一个表中取一个字段(ID)的最大值,然后赋值到一个变量(maxid)上面.我的SQL语句是 sql="select MAX(ID) into maxid from table1",不能执行.请教一下高手这个sql句该怎么写?
...全文
139 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yifengtpf 2007-09-09
  • 打赏
  • 举报
回复
select Max(id) maxid from table1;
joejoe1991 2007-09-09
  • 打赏
  • 举报
回复
declare @maxid int;
select @maxid=max(id) from table
wangyananlove 2007-09-09
  • 打赏
  • 举报
回复
rs = stmt.executeQuery("select MAX(ID) from table1");
if(rs.next()) maxid = rs.getInt(1)
这样写代码多一点但不容易出错
wangyananlove 2007-09-09
  • 打赏
  • 举报
回复
你用的是什么数据库啊
要是sqlserver当然不行了
psychic0111 2007-09-09
  • 打赏
  • 举报
回复
rs = ment.executeQuery("select MAX(ID) as maxid from table1");
if(rs.next()) maxid = rs.getInt("maxid");
kqw1981 2007-09-08
  • 打赏
  • 举报
回复
操!!建Sequnce
Joey 2007-09-08
  • 打赏
  • 举报
回复
大家帮帮忙啊,我改成 sql="select MAX(ID) into "+maxid+" from table1"也不行啊,用ResultSet好麻烦啊,我只要ID字段的那一个最大值用一下就可以了.
阿甘1976 2007-09-08
  • 打赏
  • 举报
回复
rs = stmt.executeQuery("select MAX(ID) from table1");
if(rs.next()) maxid = rs.getInt(1)

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧