如果resultset与整个行值匹配,如何获取值?

时间:2015-11-03 01:26:03

标签: java vector resultset

我附上了我的代码。如果stateVector包含statename,我只需检查整行,而不是所有icd和dicd向量值。我需要怎么做?

在我的代码中,一旦状态名与任何其他向量或icdid匹配,它就会检查所有向量,并显示它可用。

public class LCDEdits 
{   

@SuppressWarnings("unchecked")
public String validateICD_CPT(String cptCode,  String stateName, String icdCode) throws Exception
{

    /**** Variable Initialization ***/
    String lcdRes = null;
    StringBuffer lcdSql = null;
//  String error = null;

    java.sql.Connection con = null;
    java.sql.PreparedStatement poStmt1 = null;      
    DBConfig db1 = null;
    ResultSet rs = null;

    JSONObject JObj = new JSONObject(); 

    try
    {
        lcdSql = new StringBuffer(" SELECT cpt.hcpc_code, cpt.lcd_id, statepri.state_abbr, icd.icd10_id, ");
        lcdSql.append(" dicd.icd10_id_dont FROM lcd_cpt cpt ");
        lcdSql.append(" LEFT JOIN lcd_statepri statepri ON(cpt.lcd_id = statepri.lcd_id) ");            
        //lcdSql.append(" LEFT JOIN lcd_statesec statesec ON( cpt.lcd_id = statesec.lcd_id) ");
        lcdSql.append(" LEFT JOIN lcd_icd_support icd ON( cpt.lcd_id = icd.lcd_id) ");
        lcdSql.append(" LEFT JOIN lcd_icd_dont_support dicd ON( cpt.lcd_id = dicd.lcd_id) ");
        lcdSql.append(" WHERE hcpc_code = ? ");

        db1 = new DBConfig();
        con = db1.openConn();
        poStmt1 = con.prepareStatement(lcdSql.toString());

        poStmt1.setString(1, cptCode);
        rs = poStmt1.executeQuery();                

        Vector<String> stateVector = new Vector<String>();
        Vector<String> icdVector = new Vector<String>();
        Vector<String> dicdVector = new Vector<String>();

        while(rs.next())
        {                   
            stateVector.add(rs.getString("state_abbr") );
        //  icdVector.add(rs.getString("icd10_id") );
        //  dicdVector.add(rs.getString("icd10_id_dont") ); 
            //stateVector.add(rs.getString("sec_state_abbr") );


        }


            if(stateVector.contains(stateName))
            {
                if(icdVector.contains(icdCode))
                {
                //  String lcd_icd = lcd_Id;
                    lcdRes = "CPT-Code is Available in LCD Database.";
                //  lcdRes1 = "As for the LCD-Code " +lcd_icd+ ", the CPT-Code " + cptCode + " is supported the Diagnosis " +icdCode+ " in the state of " +stateName+ ".";
                }
                else if(dicdVector.contains(icdCode))
                {   
                    lcdRes = "Medicare is not interest to pay Amount for this CPT-Code.";
                //  lcdRes1 = "As for the LCD-Code " +lcd_Id+ ", the CPT-Code " +cptCode+ " is not supported the Diagnosis " +icdCode+ " in the state of " +stateName+ ".";
                }
                else 
                {
                    lcdRes = "CPT-Code is not available in the LCD-Database.";  
                //  lcdRes1 = "As for the LCD-Code " +lcd_Id+ ", the CPT-Code " +cptCode+ " is not applicable for the Diagnosis " +icdCode+ " in the state of " +stateName+ ".";
                }
            }
            else 
            {
            //  String lcd_state = lcd_Id;
                lcdRes = "State not matched with LCD-Code.";
            //  lcdRes1 = "As for the LCD-Code " +lcd_state+ ", the CPT-Code " +cptCode+ " is not applicable in the state of " +stateName+ ".";
            }

        JObj.put("status", "success");
        JObj.put("res_msg", lcdRes);
    //  JObj.put("dis_msg", lcdRes1);
    }
    catch(Exception ex) {
        ex.printStackTrace();
        JObj.put("status", "failed");           
    }
    finally {
        rs.close();
        poStmt1.close();
        db1.closeConnection(con);           
    }
    return JObj.toString();
}
}

1 个答案:

答案 0 :(得分:0)

首先,将读数与数据库分开并处理数据。

Vector stateVector = null;

try {
     Reading data from database
} catch (the problems) {
     And handle them
} finally {
     close the connection
}

然后检查您是否有一些数据:

if (stateVector != null {
    // get the data you want, probably with a loop construct
}