数据库输出到java界面,接收并显示某列的和

tjk123456 2017-03-10 06:55:38
我想写一个关于记录收入开支的SQL数据库程序,用java打开界面,现在不知道如何用a接收金额一列的和,请求帮忙。
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;
int a=0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
ct=DriverManager.getConnection("jdbc:odbc:sql server","sa","56482913tj");
ps=ct.prepareStatement("select sum(distinct jine) from ShouRu");
rs=ps.executeQuery();
xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx
}catch(Exception e){}
finally{
try{
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
if(ct!=null){
ct.close();
}
}catch(Exception e){}
}
...全文
254 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
李德胜1995 2017-03-10
  • 打赏
  • 举报
回复
加个别名

select sum(distinct jine) total from ShouRu
然后
while(rs.next()){
		a=rs.getInt("total");
		}

62,620

社区成员

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

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