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.Bvt001A.java

/**
 * Leer Datos de paises/* w  ww. j ava 2s .com*/
 * @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
    //System.out.println(productName);
    String query = "";

    switch (productName) {
    case "Oracle":
        query += "  select * from ";
        query += " ( select query.*, rownum as rn from";
        query += " (SELECT trim(codgrup), trim(desgrup)";
        query += " FROM BVT001A";
        query += " WHERE CODGRUP||desgrup like '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " AND   codgrup like '" + codgrup + "%'";
        query += " AND   instancia = '" + instancia + "'";
        query += " order by " + sortField + ") query";
        query += " ) where rownum <= " + pageSize;
        query += " and rn > (" + first + ")";
        break;
    case "PostgreSQL":
        query += " SELECT trim(codgrup), trim(desgrup)";
        query += " FROM BVT001A";
        query += " WHERE CODGRUP||desgrup like '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " AND   codgrup like '" + codgrup + "%'";
        query += " AND   instancia = '" + instancia + "'";
        query += " order by " + sortField;
        query += " LIMIT " + pageSize;
        query += " OFFSET " + first;
        break;
    case "Microsoft SQL Server":
        query += " SELECT TOP " + pageSize + " TOT.CODGRUP, TOT.DESGRUP,  TOT.ROW_NUM ";
        query += " FROM (SELECT ";
        query += "       ROW_NUMBER() OVER (ORDER BY A.CODGRUP ASC) AS ROW_NUM, ";
        query += "       A.CODGRUP, ";
        query += "       A.DESGRUP ";
        query += "       FROM BVT001A A) TOT ";
        query += " WHERE ";
        query += " TOT.CODGRUP + TOT.DESGRUP LIKE '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " AND   tot.codgrup like '" + codgrup + "%'";
        query += " AND   tot.instancia = '" + instancia + "'";
        query += " AND TOT.ROW_NUM > " + first;
        query += " ORDER BY " + sortField;
        break;
    }

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

    r = pstmt.executeQuery();

    while (r.next()) {
        Bvt001A select = new Bvt001A();
        select.setcodgrup(r.getString(1));
        select.setdesgrup(r.getString(2));

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

}

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

/**
 * Leer registros en la tabla//from  www .j ava2s .c  om
 * @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 = "";

        switch (productName) {
        case "Oracle":
            query = "SELECT count_instancias('" + ((String) filterValue).toUpperCase() + "') from dual";
            break;
        case "PostgreSQL":
            query = "SELECT count_instancias('" + ((String) filterValue).toUpperCase() + "')";
            break;
        case "Microsoft SQL Server":
            query = "SELECT DBO.count_instancias('" + ((String) filterValue).toUpperCase() + "')";
            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.Bvtcat1.java

/**
 * Leer Datos de paises/*from w w w. ja va 2 s  . c  o  m*/
 * @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

    String query = "";

    switch (productName) {
    case "Oracle":
        query += "  select * from ";
        query += " ( select query.*, rownum as rn from";
        query += " (SELECT trim(codcat1), trim(descat1)";
        query += " FROM BVTcat1";
        query += " WHERE codcat1||descat1 like '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " and codcat1 like '%" + codcat1.toUpperCase() + "%'";
        query += " AND   instancia = '" + instancia + "'";
        query += " order by " + sortField + ") query";
        query += " ) where rownum <= " + pageSize;
        query += " and rn > (" + first + ")";
        break;
    case "PostgreSQL":
        query += " SELECT trim(codcat1), trim(descat1) ";
        query += " FROM BVTcat1";
        query += " WHERE codcat1||descat1 like '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " and codcat1 like '%" + codcat1.toUpperCase() + "%'";
        query += " AND   instancia = '" + instancia + "'";
        query += " order by " + sortField;
        query += " LIMIT " + pageSize;
        query += " OFFSET " + first;
        break;
    case "Microsoft SQL Server":
        query += " SELECT * ";
        query += " FROM (SELECT  ";
        query += "      ROW_NUMBER() OVER (ORDER BY CODCAT1 ASC) AS ROW_NUM,  ";
        query += "      CODCAT1,  ";
        query += "      DESCAT1  ";
        query += "      FROM BVTCAT1) TOT  ";
        query += " WHERE  ";
        query += " TOT.CODCAT1 + TOT.DESCAT1 LIKE '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " AND TOT.CODCAT1 LIKE '%" + codcat1.toUpperCase() + "%'";
        query += " AND   tot.instancia = '" + instancia + "'";
        query += " AND TOT.ROW_NUM <= " + pageSize;
        query += " AND TOT.ROW_NUM > " + first;
        query += " ORDER BY " + sortField;
        break;
    }

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

    r = pstmt.executeQuery();

    while (r.next()) {
        Bvtcat1 select = new Bvtcat1();
        select.setcodcat1(r.getString(1));
        select.setDescat1(r.getString(2));

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

}

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

/**
 * Leer Datos de paises//from   w w w. j a va  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

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.ANOCAL, A.MESCAL,  TO_CHAR(A.FECINI, 'DD/MM/YYYY') AS FECINI,  TO_CHAR(A.FECFIN, 'DD/MM/YYYY') AS FECFIN ";
    query += " FROM TUBDER03 A";
    query += " GROUP BY A.ANOCAL, A.MESCAL, A.FECINI, A.FECFIN";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY ANOCAL, MESCAL, FECINI,FECFIN " + sortField.replace("z", "");

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

    r = pstmt.executeQuery();

    while (r.next()) {
        Cst003 select = new Cst003();
        select.setZanocal(r.getString(1));
        select.setZmescal(r.getString(2));
        select.setZfecini(r.getString(3));
        select.setZfecfin(r.getString(4));

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

}

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

/**
 * Leer Datos de paises//from  w  w  w. j ava  2 s .c o m
 * @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

    String query = "";

    switch (productName) {
    case "Oracle":
        query += "  select * from ";
        query += " ( select query.*, rownum as rn from";
        query += " (SELECT trim(CODROL), trim(DESROL)";
        query += " FROM BVT003";
        query += " WHERE codrol||desrol like '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " and codrol like '%" + codrol.toUpperCase() + "%'";
        query += " AND   instancia = '" + instancia + "'";
        query += " order by " + sortField + ") query";
        query += " ) where rownum <= " + pageSize;
        query += " and rn > (" + first + ")";
        break;
    case "PostgreSQL":
        query += " SELECT trim(codrol), trim(desrol) ";
        query += " FROM BVT003";
        query += " WHERE codrol||desrol like '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " and codrol like '%" + codrol.toUpperCase() + "%'";
        query += " AND   instancia = '" + instancia + "'";
        query += " order by " + sortField;
        query += " LIMIT " + pageSize;
        query += " OFFSET " + first;
        break;
    case "Microsoft SQL Server":
        query += " SELECT * ";
        query += " FROM (SELECT ";
        query += "       ROW_NUMBER() OVER (ORDER BY A.CODROL ASC) AS ROW_NUM, ";
        query += "       A.CODROL, ";
        query += "       A.DESROL ";
        query += "       FROM BVT003 A";
        query += "       WHERE A.CODROL + DESROL LIKE '%" + ((String) filterValue).toUpperCase() + "%') TOT";
        query += "       and a.codrol like '%" + codrol.toUpperCase() + "%'";
        query += "       AND   instancia = '" + instancia + "'";
        query += " WHERE ";
        query += " TOT.ROW_NUM <= " + pageSize;
        query += " AND TOT.ROW_NUM > " + first;
        query += " ORDER BY " + sortField;
        break;
    }

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

    r = pstmt.executeQuery();

    while (r.next()) {
        Bvt003 select = new Bvt003();
        select.setCodrol(r.getString(1));
        select.setDesrol(r.getString(2));
        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

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

/**
 * Leer Datos de paises//from w w  w. ja v a2 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

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.CODIGO, A.DESCR ";
    query += " FROM TUBDER11 A";
    query += " GROUP BY A.CODIGO, A.DESCR";
    query += " ORDER BY A.CODIGO";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY  " + sortField.replace("z", ""); //COMENTARIO MAURICIO

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

    r = pstmt.executeQuery();

    while (r.next()) {
        Tubder11 select = new Tubder11();
        select.setZcodigo(r.getString(1));
        select.setZdesc(r.getString(2));

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

}

From source file:org.orbeon.oxf.processor.sql.SQLProcessorInterpreterContext.java

public DatabaseDelegate getDelegate() {
    // Try to obtain delegate from context
    Context context = getContext(pipelineContext);
    String delegateKey = (jndiName != null) ? jndiName : datasource.toString();
    DatabaseDelegate databaseDelegate = (DatabaseDelegate) context.delegates.get(delegateKey);
    if (databaseDelegate == null) {
        // Delegate needs to be created
        try {/* w w w .j a v  a2  s.  co  m*/
            DatabaseMetaData databaseMetaData = getConnection().getMetaData();
            String productName = databaseMetaData.getDatabaseProductName();
            Class clazz = null;

            if ("oracle".equalsIgnoreCase(productName)) {
                // Try Tomcat delegate
                try {
                    getClass().getClassLoader()
                            .loadClass("org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement");
                    clazz = getClass().getClassLoader().loadClass(
                            "org.orbeon.oxf.processor.sql.delegates.SQLProcessorOracleTomcatDelegate");
                    SQLProcessor.logger.info("Using Oracle Tomcat delegate.");
                } catch (Throwable t) {
                    // Ignore
                }
                // Try JBoss 7 delegate
                // - since JBoss 7 supports JDBC 4, we shouldn't need this, and we should just be able to use SQLProcessorOracleJDBC4Delegate
                if (clazz == null) {
                    try {
                        getClass().getClassLoader()
                                .loadClass("org.jboss.jca.adapters.jdbc.WrappedPreparedStatement");
                        clazz = getClass().getClassLoader().loadClass(
                                "org.orbeon.oxf.processor.sql.delegates.SQLProcessorOracleJBoss7Delegate");
                        SQLProcessor.logger.info("Using Oracle JBoss 7 delegate.");
                    } catch (Throwable t) {
                        // Ignore
                    }
                }
                // Try JBoss 6 delegate
                if (clazz == null) {
                    try {
                        getClass().getClassLoader()
                                .loadClass("org.jboss.resource.adapter.jdbc.WrappedPreparedStatement");
                        clazz = getClass().getClassLoader().loadClass(
                                "org.orbeon.oxf.processor.sql.delegates.SQLProcessorOracleJBoss6Delegate");
                        SQLProcessor.logger.info("Using Oracle JBoss 6 delegate.");
                    } catch (Throwable t) {
                        // Ignore
                    }
                }
                // Then use the JDBC4 delegate
                if (clazz == null) {
                    clazz = SQLProcessorOracleJDBC4Delegate.class;
                    SQLProcessor.logger.info("Using Oracle JDBC4 delegate.");
                }
            } else {
                // For JDBC drivers that properly implement the API
                clazz = SQLProcessorStandardDelegate.class;
            }
            databaseDelegate = (DatabaseDelegate) clazz.newInstance();
            getContext(pipelineContext).delegates.put(delegateKey, databaseDelegate);
        } catch (Exception e) {
            throw new OXFException(e);
        }
    }
    return databaseDelegate;
}

From source file:org.talend.core.model.metadata.DBConnectionFillerImplTest.java

/**
     * Test filling catalogs for odbc teredata .
     * {@link org.talend.metadata.managment.model.DBConnectionFillerImpl#fillCatalogs(Connection, DatabaseMetaData, IMetadataConnection, List)
     * @throws SQLException/*w ww.  j  a v a 2  s  .c  o m*/
     */
@Test
public void testFillCatalogs_AS400() throws SQLException {
    // mock ReturnCode sql.Connection
    java.sql.Connection mockSqlConn = Mockito.mock(java.sql.Connection.class);
    Mockito.when(mockSqlConn.getCatalog()).thenReturn("tbi"); //$NON-NLS-1$
    // ~mock
    // mock ResultSet
    ResultSet mockCatalogResults = Mockito.mock(ResultSet.class);
    Mockito.when(mockCatalogResults.next()).thenReturn(true, false);
    Mockito.when(mockCatalogResults.getString(MetaDataConstants.TABLE_CAT.name())).thenReturn("tbi"); //$NON-NLS-1$
    ResultSet mockSchemaResults = Mockito.mock(ResultSet.class);
    Mockito.when(mockSchemaResults.next()).thenReturn(true, false);
    Mockito.when(mockSchemaResults.getString(MetaDataConstants.TABLE_SCHEM.name())).thenReturn("dbo"); //$NON-NLS-1$
    // ~Result
    // mock JDBC Metadata
    DatabaseMetaData dbJDBCMetadata = mock(DatabaseMetaData.class);
    Mockito.when(dbJDBCMetadata.getDatabaseProductName()).thenReturn(EDatabaseTypeName.AS400.getProduct());
    Mockito.when(dbJDBCMetadata.getDriverName()).thenReturn("com.ibm.as400.access.AS400JDBCDriver"); //$NON-NLS-1$
    Mockito.when(dbJDBCMetadata.getCatalogs()).thenReturn(mockCatalogResults);
    Mockito.when(dbJDBCMetadata.getConnection()).thenReturn(mockSqlConn);

    Mockito.when(dbJDBCMetadata.getSchemas()).thenReturn(mockSchemaResults);
    // ~JDBC Metadata
    //        stub(method(ConnectionUtils.class, "isOdbcTeradata", DatabaseMetaData.class)).toReturn(true); //$NON-NLS-1$
    // mock DatabaseConnection
    List<String> catalogFilter = new ArrayList<String>();
    DatabaseConnection dbConnection = mock(DatabaseConnection.class);
    Mockito.when(dbConnection.getSID()).thenReturn(""); //$NON-NLS-1$
    Mockito.when(dbConnection.getDatabaseType()).thenReturn(EDatabaseTypeName.AS400.getDisplayName());
    Mockito.when(dbConnection.getUiSchema()).thenReturn(""); //$NON-NLS-1$
    // ~DatabaseConnection

    // mock MetadataConnection
    IMetadataConnection metadaConnection = Mockito.mock(MetadataConnection.class);
    Mockito.when(metadaConnection.getDatabase()).thenReturn(""); //$NON-NLS-1$
    // ~MetadataConnection

    // mock ConvertionHelper
    PowerMockito.mockStatic(ConvertionHelper.class);
    Mockito.when(ConvertionHelper.convert(dbConnection)).thenReturn(metadaConnection);
    // Mockito.when(ExtractMetaDataUtils.getDatabaseMetaData(mockSqlConn, EDatabaseTypeName.IBMDB2ZOS.getXmlName(),
    // false, ""))
    // .thenCallRealMethod();
    // ~ConvertionHelper
    // mock ConnectionHelper
    PowerMockito.mockStatic(ConnectionHelper.class);
    Mockito.when(ConnectionHelper.getTables(dbConnection)).thenReturn(new HashSet<MetadataTable>());
    // Mockito.when(ExtractMetaDataUtils.getDatabaseMetaData(mockSqlConn, EDatabaseTypeName.IBMDB2ZOS.getXmlName(),
    // false, ""))
    // .thenCallRealMethod();
    // ~ConnectionHelper

    when(dbConnection.isContextMode()).thenReturn(false);
    List<Catalog> fillCatalogs = this.dBConnectionFillerImpl.fillCatalogs(dbConnection, dbJDBCMetadata, null,
            catalogFilter);
    assertTrue(fillCatalogs.size() == 1);
    assertTrue("tbi".equals(fillCatalogs.get(0).getName()));
    List<Schema> schemas = CatalogHelper.getSchemas(fillCatalogs.get(0));
    assertTrue(schemas.size() == 1);
    assertTrue("dbo".equals(schemas.get(0).getName()));

}

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

/**
 * Leer Datos de paises// 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 {

    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 = "";

    switch (productName) {
    case "Oracle":
        query += "  select * from ";
        query += " ( select query.*, rownum as rn from";
        query += " (SELECT trim(instancia), trim(descripcion)";
        query += " FROM instancias";
        query += " WHERE instancia||descripcion like '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " and instancia like '%" + instancia + "%'";
        query += " order by " + sortField + ") query";
        query += " ) where rownum <= " + pageSize;
        query += " and rn > (" + first + ")";
        break;
    case "PostgreSQL":
        query += " SELECT instancia, trim(descripcion) ";
        query += " FROM instancias";
        query += " WHERE cast(instancia as text)||descripcion like '%" + ((String) filterValue).toUpperCase()
                + "%'";
        query += " and cast(instancia as text) like '%" + instancia + "%'";
        query += " order by " + sortField;
        query += " LIMIT " + pageSize;
        query += " OFFSET " + first;
        break;
    case "Microsoft SQL Server":
        query += " SELECT * ";
        query += " FROM (SELECT  ";
        query += "      ROW_NUMBER() OVER (ORDER BY codigo ASC) AS ROW_NUM,  ";
        query += "      instancia,  ";
        query += "      descripcion  ";
        query += "      FROM instancias) TOT  ";
        query += " WHERE  ";
        query += " TOT.instancia + TOT.descripcion LIKE '%" + ((String) filterValue).toUpperCase() + "%'";
        query += " AND TOT.instancia LIKE '%" + instancia + "%'";
        query += " AND TOT.ROW_NUM <= " + pageSize;
        query += " AND TOT.ROW_NUM > " + first;
        query += " ORDER BY " + sortField;
        break;
    }

    pstmt = con.prepareStatement(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        Instancias select = new Instancias();
        select.setInstancia(r.getString(1));
        select.setDescripcion(r.getString(2));

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

}

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

/**
 * Leer Datos de paises/*w ww  .ja  v a 2  s .co  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

    //Consulta paginada
    String query = "SELECT * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.ANOCAL, A.MESCAL, TO_CHAR(A.FECINI, 'DD/MM/YYYY') AS FECINI,  TO_CHAR(A.FECFIN, 'DD/MM/YYYY') AS FECFIN, A.SEMCAL ";
    query += " FROM TUBDER03A A";
    query += " GROUP BY A.ANOCAL, A.MESCAL, A.FECINI, A.FECFIN, A.SEMCAL";
    query += ")query ) ";
    query += " WHERE ROWNUM <=" + pageSize;
    query += " AND rn > (" + first + ")";
    query += " ORDER BY ANOCAL, MESCAL, SEMCAL, FECINI,FECFIN " + sortField.replace("z", "");

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

    r = pstmt.executeQuery();

    while (r.next()) {
        Cst004 select = new Cst004();
        select.setZanocal(r.getString(1));
        select.setZmescal(r.getString(2));
        select.setZfecini(r.getString(3));
        select.setZfecfin(r.getString(4));
        select.setZsemana(r.getString(5));

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

}