0

次の 12 のメトリクス (TotalEmail、SentEmail など) を収集したいと考えています。そのために、ローカルメソッド (getValues()) を使用しています。その中で、12 個の Statement オブジェクトと ResultSet オブジェクトを使用しています。正常に動作しています。変数のメモリ使用量を減らす他の方法を教えてください。

getValues() {

private Statement TotalEmail    =   null;
private Statement SentEmail     =   null;
private Statement FailEmail     =   null;   
private Statement ActiveUser    =   null;
private Statement FailLogin     =   null;
private Statement SentLogin     =   null;   
private Statement TotalBilling  =   null;
private Statement FailBilling   =   null;
private Statement SuccessBilling=   null;
private Statement TotalSubmission   =   null;
private Statement FailSubmission    =   null;
private Statement SuccessSubmission =   null;

private ResultSet TotalEmailRS  =   null;
private ResultSet SentEmailRS   =   null;
private ResultSet FailEmailRS   =   null;
private ResultSet ActiveUserRS  =   null;
private ResultSet FailLoginRS   =   null;
private ResultSet SentLoginRS   =   null;
private ResultSet TotalBillingRS    =   null;
private ResultSet FailBillingRS     =   null;
private ResultSet SuccessBillingRS  =   null;
private ResultSet TotalSubmissionRS =   null;
private ResultSet FailSubmissionRS  =   null;
private ResultSet SuccessSubmissionRS   =   null;

}

4

1 に答える 1

0

次の解決策をお勧めします。

クエリごとに特定の mysql クエリを作成する代わりに、クエリ関数が 1 つだけになるようにコードを調整できますか?

私はこのようにします:

//As 'parameters' I would write String colMatch, but you adapt it to your needs
private String getTotalEmail( ...parameters... ){ 
    return getDataMysql(column, table, colMatch);
}

private String getDataMysql(String column, String table, String colMatch){
          PreparedStatement query = null;
          ResultSet rs = null;
          String data = "";
          try{
            String queryQ = "SELECT " + column + " FROM " + table +
                    " WHERE " + column + " = '" + colMatch + "' ";
            query = Connection.getConnection().prepareStatement(queryQ);
            rs = query.executeQuery(queryQ);

            //if you know there will be only one possible value found
            while ( rs.next() ){
                data = rs.getString(column);
            }          
        }catch(Exception e){
            System.out.println(e);
            System.out.println("Error query getDataMysql");
        }finally{
            // code for closing connection
        }
        return data;
    }

それが役に立てば幸い!

于 2013-08-09T12:38:08.287 に答える