Example usage for java.sql DatabaseMetaData getDatabaseProductName

List of usage examples for java.sql DatabaseMetaData getDatabaseProductName

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getDatabaseProductName.

Prototype

String getDatabaseProductName() throws SQLException;

Source Link

Document

Retrieves the name of this database product.

Usage

From source file:org.openbizview.util.Indh01.java

/**
 * Leer Datos de paises//from   w ww. j  av  a2 s  .c  o  m
 * @throws NamingException 
* @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    //System.out.println("entre al metodo SELECT");   
    Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup(JNDI);
    con = ds.getConnection();
    //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
    DatabaseMetaData databaseMetaData = con.getMetaData();
    productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin
    limpiarValores();

    if (codcia == null) {
        codcia = " - ";
    }
    if (codcia == "") {
        codcia = " - ";
    }
    if (codubi == null) {
        codubi = " - ";
    }
    if (codubi == "") {
        codubi = " - ";
    }
    if (anocal == null) {
        anocal = "";
    }
    if (semcal == null) {
        semcal = "";
    }

    String[] veccia = codcia.split("\\ - ", -1);
    String[] vecubi = codubi.split("\\ - ", -1);
    String[] vecsem = semcal.split("\\ - ", -1);

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.TOTTON, A.TOTSCP, A.TOTUSD, B.DESCIA, C.DESUBI, TO_CHAR(D.FECINI,'DD/MM/YY') AS FECINI, TO_CHAR(D.FECFIN,'DD/MM/YY') AS FECFIN ";
    query += " FROM INDH01 A, INDT03 B, INDT04 C, TUBDER03A D";
    query += " WHERE A.CODCIA = B.CODCIA";
    query += " AND A.CODUBI = C.CODUBI";
    query += " AND A.ANOCAL = D.ANOCAL";
    query += " AND A.SEMCAL = D.SEMCAL";
    query += " AND TRIM(A.CODCIA) LIKE TRIM('%" + veccia[0] + "%')";
    query += " AND TRIM(A.CODUBI) LIKE TRIM('%" + vecubi[0] + "%')";
    query += " AND TRIM(A.ANOCAL) LIKE TRIM('%" + anocal + "%')";
    query += " AND TRIM(A.SEMCAL) LIKE TRIM('%" + vecsem[0] + "%')";
    query += " GROUP BY A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.TOTTON, A.TOTSCP, A.TOTUSD, B.DESCIA, C.DESUBI, D.FECINI, D.FECFIN";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY CODCIA, CODUBI, ANOCAL, SEMCAL" + sortField.replace("z", "");

    pstmt = con.prepareStatement(query);
    //System.out.println(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Indh01 select = new Indh01();
        select.setZcodcia(r.getString(1));
        select.setZcodubi(r.getString(2));
        select.setZanocal(r.getString(3));
        select.setZsemcal(r.getString(4));
        select.setZtotton(r.getString(5));
        select.setZtotscp(r.getString(6));
        select.setZtotusd(r.getString(7));
        select.setZciadesc(r.getString(1) + " - " + r.getString(8));
        select.setZubidesc(r.getString(2) + " - " + r.getString(9));
        select.setZdesc1(r.getString(8));
        select.setZdesc2(r.getString(9));
        select.setZsemana(r.getString(4) + " - " + r.getString(10) + " al " + r.getString(11));

        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.openbizview.util.Indh04.java

/**
 * Leer Datos de paises// ww  w . ja va  2  s.c om
 * @throws NamingException 
* @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    //System.out.println("entre al metodo SELECT");   
    Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup(JNDI);
    con = ds.getConnection();
    //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
    DatabaseMetaData databaseMetaData = con.getMetaData();
    productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin

    if (codcia == null) {
        codcia = " - ";
    }
    if (codcia == "") {
        codcia = " - ";
    }
    if (codubi == null) {
        codubi = " - ";
    }
    if (codubi == "") {
        codubi = " - ";
    }
    if (anocal == null) {
        anocal = "";
    }
    if (semcal == null) {
        semcal = "";
    }

    String[] veccia = codcia.split("\\ - ", -1);
    String[] vecubi = codubi.split("\\ - ", -1);
    String[] vecsem = semcal.split("\\ - ", -1);

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.TOTPES, A.TOTUSD, A.USDKGR, B.DESCIA, C.DESUBI, TO_CHAR(D.FECINI,'DD/MM/YY') AS FECINI, TO_CHAR(D.FECFIN,'DD/MM/YY') AS FECFIN ";
    query += " FROM INDH04 A, INDT03 B, INDT04 C, TUBDER03A D";
    query += " WHERE A.CODCIA = B.CODCIA";
    query += " AND A.CODUBI = C.CODUBI";
    query += " AND A.ANOCAL = D.ANOCAL";
    query += " AND A.SEMCAL = D.SEMCAL";
    query += " AND TRIM(A.CODCIA) LIKE TRIM('%" + veccia[0] + "%')";
    query += " AND TRIM(A.CODUBI) LIKE TRIM('%" + vecubi[0] + "%')";
    query += " AND TRIM(A.ANOCAL) LIKE TRIM('%" + anocal + "%')";
    query += " AND TRIM(A.SEMCAL) LIKE TRIM('%" + vecsem[0] + "%')";
    query += " GROUP BY A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.TOTPES, A.TOTUSD, A.USDKGR, B.DESCIA, C.DESUBI, D.FECINI, D.FECFIN";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY CODCIA, CODUBI, ANOCAL, SEMCAL " + sortField.replace("z", "");

    pstmt = con.prepareStatement(query);
    //System.out.println(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Indh04 select = new Indh04();
        select.setZcodcia(r.getString(1));
        select.setZcodubi(r.getString(2));
        select.setZanocal(r.getString(3));
        select.setZsemcal(r.getString(4));
        select.setZtotpes(r.getString(5));
        select.setZtotusd(r.getString(6));
        select.setZusdkgr(r.getString(7));
        select.setZdesc1(r.getString(8));
        select.setZdesc2(r.getString(9));
        select.setZciadesc(r.getString(1) + " - " + r.getString(8));
        select.setZubidesc(r.getString(2) + " - " + r.getString(9));
        select.setZsemana(r.getString(4) + " - " + r.getString(10) + " al " + r.getString(11));

        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.openbizview.util.Bvtcat4.java

/**
* Leer registros en la tabla//from w  w w . j ava2 s  .c  o  m
* @throws NamingException 
* @throws IOException 
**/
public void counter(Object filterValue) throws SQLException, NamingException {
    try {
        Context initContext = new InitialContext();
        DataSource ds = (DataSource) initContext.lookup(JNDI);
        con = ds.getConnection();
        //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
        DatabaseMetaData databaseMetaData = con.getMetaData();
        productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin

        String query = "";

        if (b_codcat1 == null) {
            b_codcat1 = " - ";
        }
        if (b_codcat1 == "") {
            b_codcat1 = " - ";
        }

        if (b_codcat2 == null) {
            b_codcat2 = " - ";
        }
        if (b_codcat2 == "") {
            b_codcat2 = " - ";
        }

        if (b_codcat3 == null) {
            b_codcat3 = " - ";
        }
        if (b_codcat3 == "") {
            b_codcat3 = " - ";
        }

        String[] veccodcat1 = b_codcat1.split("\\ - ", -1);
        String[] veccodcat2 = b_codcat2.split("\\ - ", -1);
        String[] veccodcat3 = b_codcat3.split("\\ - ", -1);

        switch (productName) {
        case "Oracle":
            query = "SELECT count_bvtcat4('" + ((String) filterValue).toUpperCase() + "','" + veccodcat1[0]
                    + "','" + veccodcat2[0] + "','" + veccodcat3[0] + "','" + instancia + "') from dual";
            break;
        case "PostgreSQL":
            query = "SELECT count_bvtcat4('" + ((String) filterValue).toUpperCase() + "','" + veccodcat1[0]
                    + "','" + veccodcat2[0] + "','" + veccodcat3[0] + "','" + instancia + "')";
            break;
        case "Microsoft SQL Server":
            query = "SELECT DBO.count_bvtcat4('" + ((String) filterValue).toUpperCase() + "','" + veccodcat1[0]
                    + "','" + veccodcat2[0] + "','" + veccodcat3[0] + "','" + instancia + "')";
            break;
        }

        pstmt = con.prepareStatement(query);
        //System.out.println(query);

        r = pstmt.executeQuery();

        while (r.next()) {
            rows = r.getInt(1);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();
    r.close();

}

From source file:org.openbizview.util.Pre001.java

/**
 * Leer Datos de paises//from   www. j  a v a 2 s.  c  om
 * @throws NamingException 
* @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    //System.out.println("entre al metodo SELECT");   
    Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup(JNDISB);
    con = ds.getConnection();
    //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
    DatabaseMetaData databaseMetaData = con.getMetaData();
    productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin

    if (reporte == null) {
        reporte = " - ";
    }
    if (reporte == "") {
        reporte = " - ";
    }
    if (tipval == null) {
        tipval = " - ";
    }
    if (tipval == "") {
        tipval = " - ";
    }
    String[] vecrepor = reporte.split("\\ - ", -1);
    String[] vectipv = tipval.split("\\ - ", -1);

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, query.ROWNUM as rn from";
    query += "(SELECT A.REPORTE, A.CODIGO, A.DESCR, A.TIPVAL, A.VALOR, COUNT(A.CODIGO) AS ROWNUM, B.DESCR AS DESC1, A.NOMBRE";
    query += " FROM R3P.dbo.PRE001 A, R3P.dbo.TUBDER12 B ";
    query += " WHERE A.TIPVAL = B.CODIGO";
    query += " AND LTRIM(RTRIM(A.REPORTE)) LIKE LTRIM(RTRIM('%" + vecrepor[0] + "%'))";
    query += " AND LTRIM(RTRIM(A.TIPVAL)) LIKE LTRIM(RTRIM('%" + vectipv[0] + "%'))";
    query += " GROUP BY A.REPORTE, A.CODIGO, A.NOMBRE, A.DESCR, A.TIPVAL, A.VALOR, B.DESCR";
    query += ")query ) sq1";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY REPORTE, CODIGO" + sortField.replace("z", "");

    pstmt = con.prepareStatement(query);
    //System.out.println(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Pre001 select = new Pre001();
        select.setZreporte(r.getString(1));
        select.setZcodigo(r.getString(2));
        select.setZnombre(r.getString(8));
        select.setZdesc(r.getString(3));
        select.setZtipval(r.getString(4) + " - " + r.getString(7));
        select.setZvalor(r.getString(5));
        select.setZcoddel(r.getString(2));
        select.setZorderby(r.getString(1) + ", " + r.getString(2));
        select.setZdesc1(r.getString(7));

        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:com.jaspersoft.jasperserver.war.common.HeartbeatBean.java

public void createDatabaseInfoCache() {
    databaseInfoCache = new HeartbeatInfoCache();

    List dataSources = new ArrayList();

    try {//from  ww w  . ja va  2  s .co m
        List jdbcDataSources = repositoryService
                .loadClientResources(FilterCriteria.createFilter(JdbcReportDataSource.class));
        if (jdbcDataSources != null)
            dataSources.addAll(jdbcDataSources);
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug("Getting JDBC data sources list failed.", e);
    }

    try {
        List jndiDataSources = repositoryService
                .loadClientResources(FilterCriteria.createFilter(JndiJdbcReportDataSource.class));
        if (jndiDataSources != null)
            dataSources.addAll(jndiDataSources);
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug("Getting JNDI data sources list failed.", e);
    }

    for (Iterator it = dataSources.iterator(); it.hasNext();) {
        ReportDataSource dataSource = (ReportDataSource) it.next();

        Map paramValues = new HashMap();

        try {
            ReportDataSourceService dataSourceService = engineService.createDataSourceService(dataSource);
            dataSourceService.setReportParameterValues(paramValues);
        } catch (Exception e) {
            if (log.isDebugEnabled())
                log.debug("Getting connection to data source failed.", e);
        }

        Connection connection = (Connection) paramValues.get(JRParameter.REPORT_CONNECTION);
        if (connection != null) {
            try {
                DatabaseMetaData metaData = connection.getMetaData();

                HeartbeatDatabaseInfo dbInfo = new HeartbeatDatabaseInfo();
                dbInfo.setDatabaseName(metaData.getDatabaseProductName());
                dbInfo.setDatabaseVersion(metaData.getDatabaseProductVersion());
                databaseInfoCache.update(dbInfo);
            } catch (SQLException e) {
                if (log.isDebugEnabled())
                    log.debug("Getting database metadata failed.", e);
            } finally {
                if (connection != null) {
                    try {
                        connection.close();
                    } catch (SQLException e) {
                    }
                }
            }
        }
    }
}

From source file:org.openbizview.util.Bvt001.java

/**
 * Leer Datos de paises//  w  ww .ja  v a  2 s . co  m
 * @throws SQLException 
 * @throws ClassNotFoundException 
 * @throws NamingException
 * @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup(JNDI);
    con = ds.getConnection();

    //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
    DatabaseMetaData databaseMetaData = con.getMetaData();
    productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin

    if (codgrup == null) {
        codgrup = " - ";
    }
    if (codgrup == "") {
        codgrup = " - ";
    }

    String[] veccodgrup = codgrup.split("\\ - ", -1);

    String query = "";

    switch (productName) {
    case "Oracle":
        query += "  select * from ";
        query += " ( select query.*, rownum as rn from";
        query += " (SELECT trim(A.CODREP), trim(A.DESREP), trim(A.COMREP), trim(A.CODGRUP), trim(B.DESGRUP), a.instancia";
        query += " FROM BVT001 A, BVT001A B";
        query += " WHERE A.CODGRUP=B.CODGRUP(+)";
        query += " AND A.CODREP||A.DESREP LIKE trim('%" + ((String) filterValue).toUpperCase() + "%') ";
        query += " AND   A.CODREP  IN (SELECT B_CODREP FROM BVT007 WHERE B_CODROL IN (SELECT B_CODROL FROM BVT002 WHERE CODUSER = '"
                + login + "' and instancia ='" + instancia
                + "' UNION ALL SELECT B_CODrol FROM BVT008 WHERE CODUSER = '" + login + "' and instancia = '"
                + instancia + "'))";
        query += " AND   A.instancia = '" + instancia + "'";
        query += " AND   A.codrep like '" + codrep + "%'";
        if (!veccodgrup[0].equals("")) {
            query += " AND   A.CODGRUP  LIKE trim('" + veccodgrup[0].toUpperCase() + "%')";
        }
        query += " order by " + sortField.replace("v", "") + ") query";
        query += " ) where rownum <= " + pageSize;
        query += " and rn > (" + first + ")";
        break;
    case "PostgreSQL":
        query += " SELECT trim(A.CODREP), trim(A.DESREP), trim(A.COMREP), trim(A.CODGRUP), trim(fn_desgrup(A.CODGRUP)), a.instancia ";
        query += " FROM BVT001 A ";
        query += " where A.CODREP||A.DESREP LIKE trim('%" + ((String) filterValue).toUpperCase() + "%') ";
        query += " AND   A.CODREP  IN (SELECT B_CODREP FROM BVT007 WHERE B_CODROL IN (SELECT B_CODROL FROM BVT002 WHERE CODUSER = '"
                + login + "' and instancia ='" + instancia
                + "' UNION ALL SELECT B_CODrol FROM BVT008 WHERE CODUSER = '" + login + "' and instancia = '"
                + instancia + "'))";
        query += " AND   A.instancia = '" + instancia + "'";
        query += " AND   A.codrep like '" + codrep + "%'";
        if (!veccodgrup[0].equals("")) {
            query += " AND   A.CODGRUP  LIKE trim('" + veccodgrup[0].toUpperCase() + "%')";
        }
        query += " order by " + sortField.replace("v", "");
        query += " LIMIT " + pageSize;
        query += " OFFSET " + first;
        break;
    case "Microsoft SQL Server":
        query += " SELECT TOP " + pageSize;
        query += " TOT.CODREP, ";
        query += " TOT.DESREP, ";
        query += " TOT.COMREP, ";
        query += " TOT.CODGRUP, ";
        query += " TOT.DESGRUP ";
        query += " TOT.instancia ";
        query += " FROM (SELECT ";
        query += "      ROW_NUMBER() OVER (ORDER BY A.CODREP ASC) AS ROW_NUM ";
        query += "      ,A.CODREP AS CODREP ";
        query += "      ,A.DESREP AS DESREP ";
        query += "      ,A.COMREP AS COMREP ";
        query += "      ,A.CODGRUP AS CODGRUP ";
        query += "      ,B.DESGRUP AS DESGRUP ";
        query += "      FROM BVT001 A LEFT OUTER JOIN BVT001A B ON A.CODGRUP = B.CODGRUP ";
        query += "      WHERE ";
        query += "      A.CODREP + A.DESREP LIKE ('" + ((String) filterValue).toUpperCase() + "%') ";
        query += " AND   A.instancia = '" + instancia + "'";
        query += " AND   A.codrep like '" + codrep + "%'";
        if (!veccodgrup[0].equals("")) {
            query += " AND A.CODGRUP LIKE '" + veccodgrup[0].toUpperCase() + "%'";
        }
        query += "      AND A.CODREP IN (SELECT ";
        query += "                   B_CODREP ";
        query += "                   FROM  ";
        query += "                   BVT007 ";
        query += "                   WHERE ";
        query += "                   B_CODROL = '" + vlRol + "')) TOT ";
        query += " WHERE ";
        query += " TOT.ROW_NUM > " + first;
        query += " ORDER BY " + sortField.replace("v", "");
        break;
    }
    //System.out.println(query);
    pstmt = con.prepareStatement(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Bvt001 select = new Bvt001();
        select.setCodrep(r.getString(1));
        select.setDesrep(r.getString(2));
        select.setComrep(r.getString(3));
        select.setVgrupo(r.getString(4));
        select.setVgrupodesgrupo(r.getString(5));
        select.setVinstancia(r.getString(6));
        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();
}

From source file:org.openbizview.util.Indh06.java

/**
 * Leer Datos de paises// ww w .ja v a 2  s  . com
 * @throws NamingException 
* @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    //System.out.println("entre al metodo SELECT");   
    Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup(JNDI);
    con = ds.getConnection();
    //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
    DatabaseMetaData databaseMetaData = con.getMetaData();
    productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin

    if (codcia == null) {
        codcia = " - ";
    }
    if (codcia == "") {
        codcia = " - ";
    }
    if (codubi == null) {
        codubi = " - ";
    }
    if (codubi == "") {
        codubi = " - ";
    }
    if (anocal == null) {
        anocal = "";
    }
    if (semcal == null) {
        semcal = "";
    }

    String[] veccia = codcia.split("\\ - ", -1);
    String[] vecubi = codubi.split("\\ - ", -1);
    String[] vecsem = semcal.split("\\ - ", -1);

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.TOTINT, A.TOTEXP, B.DESCIA, C.DESUBI, TO_CHAR(D.FECINI,'DD/MM/YY') AS FECINI, TO_CHAR(D.FECFIN,'DD/MM/YY') AS FECFIN";
    query += " FROM INDH06 A, INDT03 B, INDT04 C, TUBDER03A D";
    query += " WHERE A.CODCIA = B.CODCIA";
    query += " AND A.CODUBI = C.CODUBI";
    query += " AND A.ANOCAL = D.ANOCAL";
    query += " AND A.SEMCAL = D.SEMCAL";
    query += " AND TRIM(A.CODCIA) LIKE TRIM('%" + veccia[0] + "%')";
    query += " AND TRIM(A.CODUBI) LIKE TRIM('%" + vecubi[0] + "%')";
    query += " AND TRIM(A.ANOCAL) LIKE TRIM('%" + anocal + "%')";
    query += " AND TRIM(A.SEMCAL) LIKE TRIM('%" + vecsem[0] + "%')";
    query += " GROUP BY A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.TOTINT, A.TOTEXP, B.DESCIA, C.DESUBI, D.FECINI, D.FECFIN";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY CODCIA, CODUBI, ANOCAL, SEMCAL " + sortField.replace("z", "");

    pstmt = con.prepareStatement(query);
    //System.out.println(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Indh06 select = new Indh06();
        select.setZcodcia(r.getString(1));
        select.setZcodubi(r.getString(2));
        select.setZanocal(r.getString(3));
        select.setZsemcal(r.getString(4));
        select.setZtotint(r.getString(5));
        select.setZtotexp(r.getString(6));
        select.setZdesc1(r.getString(7));
        select.setZdesc2(r.getString(8));
        select.setZciadesc(r.getString(1) + " - " + r.getString(7));
        select.setZubidesc(r.getString(2) + " - " + r.getString(8));
        select.setZvendesc(r.getString(3) + " - " + r.getString(9));
        select.setZsemana(r.getString(4) + " - " + r.getString(9) + " al " + r.getString(10));

        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.openbizview.util.Indh19.java

/**
 * Leer Datos de paises/* w w w. j a va2 s  .c o m*/
 * @throws NamingException 
* @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    //System.out.println("entre al metodo SELECT");   
    Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup(JNDI);
    con = ds.getConnection();
    //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
    DatabaseMetaData databaseMetaData = con.getMetaData();
    productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin

    if (codcia == null) {
        codcia = " - ";
    }
    if (codcia == "") {
        codcia = " - ";
    }
    if (codubi == null) {
        codubi = " - ";
    }
    if (codubi == "") {
        codubi = " - ";
    }
    if (anocal == null) {
        anocal = "";
    }
    if (semcal == null) {
        semcal = "";
    }

    String[] veccia = codcia.split("\\ - ", -1);
    String[] vecubi = codubi.split("\\ - ", -1);
    String[] vecsem = semcal.split("\\ - ", -1);

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.tonpre, A.totrea, A.usdpre, A.usdrea, B.DESCIA, C.DESUBI, TO_CHAR(D.FECINI,'DD/MM/YY') AS FECINI, TO_CHAR(D.FECFIN,'DD/MM/YY') AS FECFIN ";
    query += " FROM INDH19 A, INDT03 B, INDT04 C, TUBDER03A D";
    query += " WHERE A.CODCIA = B.CODCIA";
    query += " AND A.CODUBI = C.CODUBI";
    query += " AND A.ANOCAL = D.ANOCAL";
    query += " AND A.SEMCAL = D.SEMCAL";
    query += " AND TRIM(A.CODCIA) LIKE TRIM('%" + veccia[0] + "%')";
    query += " AND TRIM(A.CODUBI) LIKE TRIM('%" + vecubi[0] + "%')";
    query += " AND TRIM(A.ANOCAL) LIKE TRIM('%" + anocal + "%')";
    query += " AND TRIM(A.SEMCAL) LIKE TRIM('%" + vecsem[0] + "%')";
    query += " GROUP BY A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.tonpre, A.totrea, A.usdpre, A.usdrea, B.DESCIA, C.DESUBI, D.FECINI, D.FECFIN";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY CODCIA, CODUBI, ANOCAL, SEMCAL " + sortField.replace("z", "");

    pstmt = con.prepareStatement(query);
    //System.out.println(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Indh19 select = new Indh19();
        select.setZcodcia(r.getString(1));
        select.setZcodubi(r.getString(2));
        select.setZanocal(r.getString(3));
        select.setZsemcal(r.getString(4));
        select.setZtonpre(r.getString(5));
        select.setZtotrea(r.getString(6));
        select.setZusdpre(r.getString(7));
        select.setZusdrea(r.getString(8));
        select.setZdesc1(r.getString(9));
        select.setZdesc2(r.getString(10));
        select.setZciadesc(r.getString(1) + " - " + r.getString(9));
        select.setZubidesc(r.getString(2) + " - " + r.getString(10));
        select.setZsemana(r.getString(4) + " - " + r.getString(11) + " al " + r.getString(12));

        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.openbizview.util.Indh03.java

/**
 * Leer Datos de paises//from w w  w  .  ja  v  a  2 s. c o m
 * @throws NamingException 
* @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    //System.out.println("entre al metodo SELECT");   
    Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup(JNDI);
    con = ds.getConnection();
    //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno
    DatabaseMetaData databaseMetaData = con.getMetaData();
    productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin

    if (codcia == null) {
        codcia = " - ";
    }
    if (codcia == "") {
        codcia = " - ";
    }
    if (codubi == null) {
        codubi = " - ";
    }
    if (codubi == "") {
        codubi = " - ";
    }
    if (codren == null) {
        codren = " - ";
    }
    if (codren == "") {
        codren = " - ";
    }
    if (anocal == null) {
        anocal = "";
    }
    if (semcal == null) {
        semcal = "";
    }

    String[] veccia = codcia.split("\\ - ", -1);
    String[] vecubi = codubi.split("\\ - ", -1);
    String[] vecren = codren.split("\\ - ", -1);
    String[] vecsem = semcal.split("\\ - ", -1);

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.CODREN, A.TOTREN, B.DESCIA, C.DESUBI, D.DESREN, TO_CHAR(E.FECINI,'DD/MM/YY') AS FECINI, TO_CHAR(E.FECFIN,'DD/MM/YY') AS FECFIN ";
    query += " FROM INDH03 A, INDT03 B, INDT04 C, INDT11 D, TUBDER03A E";
    query += " WHERE A.CODCIA = B.CODCIA";
    query += " AND A.CODUBI = C.CODUBI";
    query += " AND A.CODREN = D.CODREN";
    query += " AND A.ANOCAL = E.ANOCAL";
    query += " AND A.SEMCAL = E.SEMCAL";
    query += " AND TRIM(A.CODCIA) LIKE TRIM('%" + veccia[0] + "%')";
    query += " AND TRIM(A.CODUBI) LIKE TRIM('%" + vecubi[0] + "%')";
    query += " AND TRIM(A.ANOCAL) LIKE TRIM('%" + anocal + "%')";
    query += " AND TRIM(A.SEMCAL) LIKE TRIM('%" + vecsem[0] + "%')";
    query += " AND TRIM(A.CODREN) LIKE TRIM('%" + vecren[0] + "%')";
    query += " GROUP BY A.CODCIA, A.CODUBI, A.ANOCAL, A.SEMCAL, A.CODREN, A.TOTREN, B.DESCIA, C.DESUBI, D.DESREN, E.FECINI, E.FECFIN";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY CODCIA, CODUBI, ANOCAL, SEMCAL" + sortField.replace("z", "");

    pstmt = con.prepareStatement(query);
    //System.out.println(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Indh03 select = new Indh03();
        select.setZcodcia(r.getString(1));
        select.setZcodubi(r.getString(2));
        select.setZanocal(r.getString(3));
        select.setZsemcal(r.getString(4));
        select.setZcodrendel(r.getString(5));
        select.setZcodren(r.getString(5) + " - " + r.getString(9));
        select.setZtotren(r.getString(6));
        select.setZciadesc(r.getString(1) + " - " + r.getString(7));
        select.setZubidesc(r.getString(2) + " - " + r.getString(8));
        select.setZdesc1(r.getString(7));
        select.setZdesc2(r.getString(8));
        select.setZdesc3(r.getString(9));
        select.setZsemana(r.getString(4) + " - " + r.getString(10) + " al " + r.getString(11));

        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.apache.torque.task.TorqueSQLExec.java

/**
 * Verify if connected to the correct RDBMS
 *
 * @param conn//www .jav a 2s  .c  o  m
 */
protected boolean isValidRdbms(Connection conn) {
    if (rdbms == null && version == null) {
        return true;
    }

    try {
        DatabaseMetaData dmd = conn.getMetaData();

        if (rdbms != null) {
            String theVendor = dmd.getDatabaseProductName().toLowerCase();

            log("RDBMS = " + theVendor, Project.MSG_VERBOSE);
            if (theVendor == null || theVendor.indexOf(rdbms) < 0) {
                log("Not the required RDBMS: " + rdbms, Project.MSG_VERBOSE);
                return false;
            }
        }

        if (version != null) {
            String theVersion = dmd.getDatabaseProductVersion().toLowerCase();

            log("Version = " + theVersion, Project.MSG_VERBOSE);
            if (theVersion == null
                    || !(theVersion.startsWith(version) || theVersion.indexOf(" " + version) >= 0)) {
                log("Not the required version: \"" + version + "\"", Project.MSG_VERBOSE);
                return false;
            }
        }
    } catch (SQLException e) {
        // Could not get the required information
        log("Failed to obtain required RDBMS information", Project.MSG_ERR);
        return false;
    }

    return true;
}