mysql中Select中SUM用法的问题,请赐教!
gzrzDhSl字段为int型;
sql = "select sum(gzrzDhSl) as t1 from gzrz where bmId = "+bmId+ " ";
rs = stmt.executeQuery(sql);
if(rs.next())
{
out.println(rs.getString(t1));
}
出现下列错误:
java.lang.NullPointerException at com.mysql.jdbc.Statement.executeQuery(Unknown Source)
at com.mysql.jdbc.jdbc2.Statement.executeQuery(Unknown Source)
at com.base.db.DBConn.execSQL(DBConn.java:118)
at _yggl._mainlist__jsp._jspService(/yggl/mainlist.jsp:43)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:534)
------解决方案--------------------和版本没得关系的
你的错误是java.lang.
NullPointerException,
空指针,你访问了一个空的变量.
out.println(rs.getInt(1));看看
------解决方案--------------------确认bmId是有值吗