如何使用该列的模式更新特定列的空单元格? (使用Java的Sql)

时间:2016-01-01 12:35:24

标签: java sql sql-server

我使用以下代码计算列的模式:

   public void CalcCatValMean(String colName , String tableName){
    Statement st = null;
    String sql = null;
    String mode = null;

    try{

        setConnection();
        st = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);

        sql = "SELECT " + colName + " , Count(colName) AS Frequency FROM " +   tableName + " GROUP BY " + colName + " HAVING Count(colName) >= ALL (SELECT  Count(colName) FROM " + tableName + " GROUP BY " + colName + " )";
        System.out.println("sql :" + sql);

        ResultSet rset = st.executeQuery(sql);
        CachedRowSet rowset = new CachedRowSetImpl();
        rowset.populate(rset);

        int i = 1;
        while(rowset.next()) {  // check if a result was returned
              mode = rowset.getString(i); // get your result
              System.out.println("mode is : " + mode);
              i++;
            }

        //Clean-up environment
        st.close(); 
        closeConnection();

    }
    catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

但奇怪的是它的'也计算'null“作为一个值&将以下列的输出作为“null”。

  • ABC
  • XYZ

我想要做的是计算除null之外的该列的所有值的模式,然后使用计算模式更新该列的空单元格。

0 个答案:

没有答案