怎么在java中把sql数据库一列求和,把求和结果显示在jsp页面上?
我是新手啊,我把数据里的数据全取出来放在ArrayList里面了,但是我想让km(数据库第十列)这一列的数求和,然后把结果显示在jsp页面上,该怎么做?jsp页面上怎么接...
我是新手啊,我把数据里的数据全取出来放在ArrayList里面了,但是我想让km(数据库第十列)这一列的数求和,然后把结果显示在jsp页面上,该怎么做?jsp页面上怎么接收?拜求各位大神帮忙指导啊。我具体的servlet代码如下。有count的地方都报错了,说是count cannot be resolved to a variable。
try{
Connection conn=null;
Statement st=null;
Class.forName("com.mysql.jdbc.Driver");
conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=");
st =conn.createStatement();
String sql1="select sum(km) as count from jixiao2;"
st.execute(sql);
} catch (Exception e)
{
e.printStackTrace();
}
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
ResultSet rssumkm1=stmt.executeQuery(sql1);
ResultSet rs=pstmt.executeQuery();
while(rs.next())
{
Jixiao jx=new Jixiao();
jx.setKm(rs.getInt(10));
jx.setAllowance(rs.getInt(11));
jx.setCount(rssumkm1.getInt(count));
list.add(jx);
}
request.setAttribute("Count", count);
request.setAttribute("list", list);
request.getRequestDispatcher("Showlist.jsp").forward(request, response); 展开
try{
Connection conn=null;
Statement st=null;
Class.forName("com.mysql.jdbc.Driver");
conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=");
st =conn.createStatement();
String sql1="select sum(km) as count from jixiao2;"
st.execute(sql);
} catch (Exception e)
{
e.printStackTrace();
}
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
ResultSet rssumkm1=stmt.executeQuery(sql1);
ResultSet rs=pstmt.executeQuery();
while(rs.next())
{
Jixiao jx=new Jixiao();
jx.setKm(rs.getInt(10));
jx.setAllowance(rs.getInt(11));
jx.setCount(rssumkm1.getInt(count));
list.add(jx);
}
request.setAttribute("Count", count);
request.setAttribute("list", list);
request.getRequestDispatcher("Showlist.jsp").forward(request, response); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询