【发布时间】:2018-06-26 22:58:04
【问题描述】:
这是我下面的数据库,我正在用 java 编码,我的工作区是 eclipse
我的问题是这样的:我正在尝试对每个月的列 monthlypaid 求和,例如在一月份,除了 appartmentnum :1 每个人都支付
其中值 0 表示(当月未支付)
所以一月530+530+700+660+490+200
570+530+700+200 以后
我应该像这样打印 1, 1 月 sum 2, febsum 而且我不知道该怎么做
我试过了,但我认为我离解决方案还很远
public static String select_Month_payment(String username) {
int i=1;
String answer="",ans="";
try {
PreparedStatement statement = connect.prepareStatement("select january,february,march,april,may,june,july,august,september,october,november,december from tenant where username= "+"'"+username+"'");
ResultSet result = statement.executeQuery();
while(result.next())
{
for (i=1;i<13;i++)
{
answer=result.getString(i);
if(!answer.matches("0") )
ans+= answer + " " ;
}
}
} catch (SQLException var2) {
var2.printStackTrace();
}
return ans;
}
【问题讨论】:
-
你可以发布预期的输出而不是图像吗?