【问题标题】:Average calculation of various columns of stored procedure in javajava中存储过程各列的平均计算
【发布时间】:2014-11-05 10:24:08
【问题描述】:

我有一个存储过程,其中 avg_pressure 列为空。我必须创建一种方法来计算一行中各列的平均值,并将计算出的平均值放在相应的行和列中。我的平均计算方法是:-

public int  arrayAverage() throws NumberFormatException, SQLException {
			    int sum = 0;
			    int count = 0; 
			   getConnection();
				String A= rs.getString("st1_vs1_bag1_rb");
				String B= rs.getString("st1_vs1_bag2_rb");
				String C= rs.getString("st1_vs1_bag4_rb");
			    for (int i = 0; i < a.length; i++)
			    {
			        for (int j = 0; j < a[i].length; j++)
			        {
			           
			         sum +=Integer.parseInt(A+B+C);
			      
			            count++;
                    }

我的表格数据是通过以下方法检索到的:-

public String[][] getDbTable()
		{
	
	
			int i = 0;
			String [][]a = new String[3600][16];
			System.out.println("datetime is" +d);
			System.out.println("datetime is" +currentDate);
			try
			{
	             con = getConnection();
		        
	       
	             String sql = "exec vcs_gauge @gauge_name=?,@first_rec_time=?,@last_rec_time=?";
	            DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	             System.out.println("date is "+df.format(currentDate));
	             clstmt = con.prepareCall(sql); 
	             clstmt.setString(1,"vs1_bag");
	           
	    clstmt.setString(2, "2014-09-01 10:00:00");
	    clstmt.setString(3, "2014-09-01 11:00:00");
	   
	              clstmt.execute();
	              rs = clstmt.getResultSet();
	           
				
				while (rs.next())
				{
					for(int j=0; j<16; j++)
					{
							a[i][j]	= rs.getString(j+1);
					}
				
					i++;
				}
			
			}
	
			catch( Exception e )
			{
				System.out.println("\nException in Display Bean in getDbTable(String code):"+e);
			}
			finally
			{
				
				closeConnection();
			}
			return a; 
		}

但是当我通过 jsp 运行 arrayAverage() 方法时,会引发以下异常。 com.microsoft.sqlserver.jdbc.SQLServerException: 结果集已关闭。

提前致谢。

【问题讨论】:

    标签: java sql sql-server-2012 average


    【解决方案1】:

    取决于您使用的池类型,当您关闭连接时,对象 Statement 和 ResultSet 也将被关闭。

    尝试在关闭连接之前检索您想要的数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-07
      • 2012-04-15
      • 2015-04-29
      • 1970-01-01
      • 2020-03-11
      相关资源
      最近更新 更多