what is the error message? rs.next() = null? does your sql string like "select sum(moneny) from table where ..." and actually there in none records satisfy the condition?
and you should get the value by "rs.getInteger(1)" or "rs.getInteger("sum(moneny)")"
报告是rs.next()处出错。 用select moneny from 不会错。 用select sum(moneny) from 报错。 现在 我想得到moneny的总和,而且moneny有可能为空。 怎么解决,再加分50求解,好方法再加分。
不可以select money from然后取出 money字段一个一个加起来吗?
想用sum来做,因为有很多用到的地方。
String databaseURL = "jdbc:oracle:thin:@192.168.101.15:1521:[yourDatabaseName]"; String user = "[yourUser]"; String password = "[yourPassword]"; String driverName = "oracle.jdbc.driver.OracleDriver";Class.forName(driverName); conn = DriverManager.getConnection(databaseURL, user, password);stmt = conn.createStatement() ; sql = "select * from RJ_Fortune"; System.out.println(sql); rs = stmt.executeQuery(sql);if(rs.next()) { // do something what you want to do. }
and I want to see your complete sql string. if the string is right, and the method you use is "executeQuery",and the connection is ok,then such mistake should not exist.
--->select sum(tradeNum) from MraketProTradeInfo where proId='05' and tradeSort='2'java.lang.NullPointerException
我同意yoobj的看法给查询结果取一个别名就行了
同意Fortune2k1(Forune2k1) 的观点
select sum(moneny)from 表 改为 select sum(moneny) as moneny from 表
出现这个问题是数据表是moeny这个字表有可能出现为null的时候,会出现这个问题; 最好在select sum(money) from table的时候; 使用select sum(iif(isnull(money),0,money)) form table; 现在没有办法测试,有条件测试一下,再给你准确答案
rs.next() = null?
does your sql string like "select sum(moneny) from table where ..."
and actually there in none records satisfy the condition?
rs.next()有可能为空,该怎么解决?
感谢两位
我怎么查出moneny的各字段总和?
用select moneny from 不会错。
用select sum(moneny) from 报错。
现在 我想得到moneny的总和,而且moneny有可能为空。
怎么解决,再加分50求解,好方法再加分。
String user = "[yourUser]";
String password = "[yourPassword]";
String driverName = "oracle.jdbc.driver.OracleDriver";Class.forName(driverName);
conn = DriverManager.getConnection(databaseURL, user, password);stmt = conn.createStatement() ;
sql = "select * from RJ_Fortune";
System.out.println(sql);
rs = stmt.executeQuery(sql);if(rs.next())
{
// do something what you want to do.
}
if the string is right, and the method you use is "executeQuery",and the connection is ok,then such mistake should not exist.
改为
select sum(moneny) as moneny from 表
最好在select sum(money) from table的时候;
使用select sum(iif(isnull(money),0,money)) form table; 现在没有办法测试,有条件测试一下,再给你准确答案