Search in sources :

Example 1 with ReportsParamQuery

use of org.mifos.reports.business.ReportsParamQuery in project head by mifos.

the class ReportsParamQueryDAO method listValuesOfParameters.

/**
     * This method lists all the values of parameter
     */
public List listValuesOfParameters(ReportsParams rps) throws Exception {
    List<ReportsParamQuery> alValues = new ArrayList();
    ReportsDataSource rds = rps.getReportsDataSource();
    Connection con = null;
    try {
        String driver = rds.getDriver();
        String url = rds.getUrl();
        String username = rds.getUsername();
        String password = rds.getPassword();
        if (driver != null && !driver.equals("")) {
            Class.forName(driver);
            con = DriverManager.getConnection(url, username, password);
            Statement stm = con.createStatement();
            String data = rps.getData();
            if (data != null && !data.equals("")) {
                ResultSet rs = stm.executeQuery(data);
                ResultSetMetaData rsmd = rs.getMetaData();
                while (rs.next()) {
                    ReportsParamQuery obj = new ReportsParamQuery();
                    if (rsmd.getColumnCount() >= 2) {
                        obj.setValue1(rs.getString(1));
                        obj.setValue2(rs.getString(2));
                    } else if (rsmd.getColumnCount() == 1) {
                        obj.setValue1(rs.getString(1));
                        obj.setValue2(rs.getString(1));
                    }
                    alValues.add(obj);
                }
            }
        }
    } finally {
        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return alValues;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ReportsParamQuery(org.mifos.reports.business.ReportsParamQuery) ReportsDataSource(org.mifos.reports.business.ReportsDataSource) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Aggregations

Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 ReportsDataSource (org.mifos.reports.business.ReportsDataSource)1 ReportsParamQuery (org.mifos.reports.business.ReportsParamQuery)1