List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.openbizview.util.Indh17.java
/** * Leer Datos de paises/*from w ww. 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 (anocal == null) { anocal = ""; } if (semcal == null) { semcal = ""; } String[] veccia = codcia.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.ANOCAL, A.SEMCAL, A.totusd, A.totrat, B.DESCIA, TO_CHAR(D.FECINI,'DD/MM/YY') AS FECINI, TO_CHAR(D.FECFIN,'DD/MM/YY') AS FECFIN "; query += " FROM INDH17 A, INDT03 B, TUBDER03A D"; query += " WHERE A.CODCIA = B.CODCIA"; 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.ANOCAL) LIKE TRIM('%" + anocal + "%')"; query += " AND TRIM(A.SEMCAL) LIKE TRIM('%" + vecsem[0] + "%')"; query += " GROUP BY A.CODCIA, A.ANOCAL, A.SEMCAL, A.totusd, A.totrat, B.DESCIA, D.FECINI, D.FECFIN"; query += ")query ) "; query += " WHERE ROWNUM <=" + pageSize; query += " AND rn > (" + first + ")"; query += " ORDER BY CODCIA, ANOCAL, SEMCAL " + sortField.replace("z", ""); pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Indh17 select = new Indh17(); select.setZcodcia(r.getString(1)); select.setZanocal(r.getString(2)); select.setZsemcal(r.getString(3)); select.setZtotusd(r.getString(4)); select.setZtotrat(r.getString(5)); select.setZdesc1(r.getString(6)); select.setZciadesc(r.getString(1) + " - " + r.getString(6)); select.setZsemana(r.getString(3) + " - " + r.getString(7) + " al " + r.getString(8)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openbizview.util.Instanciasusr.java
/** * Leer Datos de categoria2//from ww w.j a v a2 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 = ""; if (instancias == null) { instancias = " - "; } if (instancias == "") { instancias = " - "; } String[] veccodrol = instancias.split("\\ - ", -1); switch (productName) { case "Oracle": query += " select * from "; query += " ( select query.*, rownum as rn from"; query += " (SELECT trim(a.coduser), trim(a.instancia), trim(b.descripcion)"; query += " FROM instancias_usr a, instancias b"; query += " where a.instancia=b.instancia"; query += " and a.instancia like '" + veccodrol[0] + "%'"; query += " AND a.coduser||a.instancia||b.descripcion like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " order by " + sortField + ") query"; query += " ) where rownum <= " + pageSize; query += " and rn > (" + first + ")"; break; case "PostgreSQL": query += " SELECT trim(a.coduser), a.instancia, trim(b.descripcion)"; query += " FROM instancias_usr a, instancias b"; query += " where a.instancia=b.instancia"; query += " and cast(a.instancia as text) like '" + veccodrol[0] + "%'"; query += " AND a.coduser||cast(a.instancia as text)||b.descripcion like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " order by " + sortField; query += " LIMIT " + pageSize; query += " OFFSET " + first; break; case "Microsoft SQL Server": query += " SELECT TOP " + pageSize; query += " TOT.B_CODROL, "; query += " TOT.DESROL, "; query += " TOT.B_CODCAT1, "; query += " TOT.DESCAT1 "; query += " FROM (SELECT "; query += " ROW_NUMBER() OVER (ORDER BY A.B_CODROL ASC) AS ROW_NUM, "; query += " A.B_CODROL, "; query += " B.DESROL, "; query += " A.B_CODCAT1, "; query += " C.DESCAT1 "; query += " FROM ACCCAT1 A, BVT003 B, BVTCAT1 C "; query += " WHERE "; query += " A.B_CODROL=B.CODROL "; query += " AND A.B_CODCAT1=C.CODCAT1) TOT "; query += " WHERE "; query += " TOT.B_CODROL LIKE '" + veccodrol[0] + "%'"; query += " AND TOT.B_CODCAT1 + TOT.DESCAT1 LIKE '%" + ((String) filterValue).toUpperCase() + "%'"; 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()) { Instanciasusr select = new Instanciasusr(); select.setCoduser(r.getString(1)); select.setInstancias(r.getString(2)); select.setDescripcion(r.getString(3)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openbizview.util.Acccat1.java
/** * Leer Datos de nominas para asignar a menucheck * @throws NamingException //from w ww .j a va 2 s .co m * @throws SQLException * @throws IOException **/ private void selectAcccat1() throws NamingException, SQLException { 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 codcat1, codcat1||' - '||descat1"; query += " from bvtcat1"; query += " where instancia = '" + instancia + "'"; query += " order by codcat1"; break; case "PostgreSQL": query = "Select codcat1, codcat1||' - '||descat1"; query += " from bvtcat1"; query += " where instancia = '" + instancia + "'"; query += " order by codcat1"; break; case "Microsoft SQL Server": query = "Select codcat1, codcat1 + ' - ' + descat1"; query += " from bvtcat1"; query += " where instancia = '" + instancia + "'"; query += " order by codcat1"; break; } ////System.out.println(query); pstmt = con.prepareStatement(query); ////System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { String cat1 = new String(r.getString(1)); String descat1 = new String(r.getString(2)); listAcccat1.put(descat1, cat1); sorted = sortByValues(listAcccat1); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openbizview.util.Acccat1.java
/** * Leer registros en la tabla/* ww w. j a v a2 s . co 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_codrol == null) { b_codrol = " - "; } if (b_codrol == "") { b_codrol = " - "; } String[] veccodrol = b_codrol.split("\\ - ", -1); switch (productName) { case "Oracle": query = "SELECT count_acccat1('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[0] + "','" + instancia + "') from dual"; break; case "PostgreSQL": query = "SELECT count_acccat1('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[0] + "','" + instancia + "')"; break; case "Microsoft SQL Server": query = "SELECT DBO.count_acccat1('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[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.wso2.carbon.event.output.adapter.rdbms.RDBMSEventAdapter.java
/** * Populate specific db Mappings// ww w . jav a2 s . c om */ private void populateDbMappings() throws OutputEventAdapterException { String dbName = null; dbTypeMappings = new HashMap<String, String>(); Connection con = null; try { CarbonDataSource carbonDataSource = RDBMSEventAdapterServiceValueHolder.getDataSourceService() .getDataSource(eventAdapterConfiguration.getStaticProperties() .get(RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_DATASOURCE_NAME)); if (carbonDataSource != null) { con = ((DataSource) carbonDataSource.getDSObject()).getConnection(); DatabaseMetaData databaseMetaData = con.getMetaData(); dbName = databaseMetaData.getDatabaseProductName(); dbName = dbName.toLowerCase(); } else { throw new OutputEventAdapterException( "There is no data-source called " + eventAdapterConfiguration.getStaticProperties() .get(RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_DATASOURCE_NAME)); } } catch (DataSourceException e) { log.error("There is no data-source found by the name: " + eventAdapterConfiguration .getStaticProperties().get(RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_DATASOURCE_NAME), e); throw new ConnectionUnavailableException(e.getMessage(), e); } catch (SQLException e) { throw new ConnectionUnavailableException(e); } finally { cleanupConnections(null, con); } // Map<String, String> defaultMappings = new HashMap<String, String>(); String[] staticAttributes = { RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_STRING, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_DOUBLE, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_INTEGER, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_LONG, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_FLOAT, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_BOOLEAN, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_CREATE_TABLE, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_INSERT_DATA, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_TABLE_EXIST, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_UPDATE_TABLE, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_PROPERTY_DATA_TYPE_IN_TABLE, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_PROPERTY_SELECT_FROM_TABLE, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_COMMA, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_QUESTION_MARK, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_EQUAL, RDBMSEventAdapterConstants.ADAPTER_GENERIC_RDBMS_AND }; Boolean staticAttributeExist; String attribute = null; Map<String, String> defaultMappings = new HashMap<String, String>(); for (String staticAttribute : staticAttributes) { staticAttributeExist = false; for (Map.Entry<String, String> entry : globalProperties.entrySet()) { attribute = staticAttribute; if (staticAttribute.equals(entry.getKey())) { staticAttributeExist = true; defaultMappings.put(entry.getKey(), entry.getValue()); break; } } if (!staticAttributeExist) { throw new OutputEventAdapterRuntimeException( "A mandatory attribute " + attribute + " does not exist"); } } Boolean valueExist; for (Map.Entry<String, String> defaultMap : defaultMappings.entrySet()) { valueExist = false; for (Map.Entry<String, String> entry : globalProperties.entrySet()) { if (entry.getKey().contains(dbName)) { if (entry.getKey().contains(defaultMap.getKey())) { dbTypeMappings.put(defaultMap.getKey(), entry.getValue()); valueExist = true; break; } } } if (!valueExist) { dbTypeMappings.put(defaultMap.getKey(), defaultMap.getValue()); } } }
From source file:com.flexive.ejb.beans.configuration.GlobalConfigurationEngineBean.java
/** * {@inheritDoc}//from w w w . j a v a2 s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public DivisionData createDivisionData(int divisionId, String dataSource, String domainRegEx) { String dbVendor = "unknown"; String dbVersion = "unknown"; String dbDriverVersion = "unknown"; boolean available = false; Connection con = null; try { // lookup non-transactional datasource to avoid issues with the default JEE6 data source in Glassfish con = Database.getDataSource(dataSource + "NoTX").getConnection(); DatabaseMetaData dbmd = con.getMetaData(); dbVendor = dbmd.getDatabaseProductName(); dbVersion = dbmd.getDatabaseProductVersion(); dbDriverVersion = dbmd.getDriverName() + " " + dbmd.getDriverVersion(); available = true; } catch (NamingException e) { LOG.error("Failed to get datasource " + dataSource + " (flagged inactive)"); } catch (SQLException e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to get database meta information: " + e.getMessage(), e); } } finally { Database.closeObjects(GlobalConfigurationEngineBean.class, con, null); } return new DivisionData(divisionId, available, dataSource, domainRegEx, dbVendor, dbVersion, dbDriverVersion); }
From source file:org.openbizview.util.Acccat2.java
/** * Leer registros en la tabla//from w w w . ja v a 2s . co 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_codrol == null) { b_codrol = " - "; } if (b_codrol == "") { b_codrol = " - "; } if (b_codcat1 == null) { b_codcat1 = " - "; } if (b_codcat1 == "") { b_codcat1 = " - "; } String[] veccodrol = b_codrol.split("\\ - ", -1); String[] veccodcat1 = b_codcat1.split("\\ - ", -1); switch (productName) { case "Oracle": query = "SELECT count_acccat2('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[0] + "','" + veccodcat1[0] + "','" + instancia + "') from dual"; break; case "PostgreSQL": query = "SELECT count_acccat2('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[0] + "','" + veccodcat1[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.Maillista.java
/** * Leer Datos de mailconfig/*from w w w.j a v a2 s .co m*/ * @throws NamingException * @throws IOException **/ public void select(int first, int pageSize, String sortField, 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 (idgrupo == null) { idgrupo = " - "; } if (idgrupo.equals("")) { idgrupo = " - "; } String[] vecidgrupo = idgrupo.split("\\ - ", -1); switch (productName) { case "Oracle": query += " select * from "; query += " ( select query.*, rownum as rn from"; query += " (SELECT trim(A.IDGRUPO), trim(B.IDMAIL), trim(B.MAIL)"; query += " FROM MAILGRUPOS A, MAILLISTA B"; query += " WHERE A.IDGRUPO=B.IDGRUPO"; query += " and A.instancia=B.instancia"; query += " and a.idgrupo||b.idmail||upper(b.mail) like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and a.idgrupo like '" + vecidgrupo[0] + "%'"; query += " and b.idmail like '" + idmail + "%'"; query += " AND b.instancia = '" + instancia + "'"; query += " order by " + sortField + ") query"; query += " ) where rownum <= " + pageSize; query += " and rn > (" + first + ")"; break; case "PostgreSQL": query += " SELECT A.IDGRUPO, trim(B.IDMAIL), trim(B.MAIL)"; query += " FROM MAILGRUPOS A, MAILLISTA B"; query += " WHERE A.IDGRUPO=B.IDGRUPO"; query += " and A.instancia=B.instancia"; query += " and cast(a.idgrupo as text)||b.idmail||upper(b.mail) like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and cast(a.idgrupo as text) like '" + vecidgrupo[0] + "%'"; query += " and b.idmail like '" + idmail + "%'"; query += " AND b.instancia = '" + instancia + "'"; query += " order by " + sortField; query += " LIMIT " + pageSize; query += " OFFSET " + first; break; case "Microsoft SQL Server": query += " SELECT TOP " + pageSize; query += " A.ROW_NUM, "; query += " A.IDGRUPO, "; query += " A.IDMAIL, "; query += " A.MAIL "; query += " FROM (SELECT "; query += " ROW_NUMBER() OVER (ORDER BY A.IDGRUPO ASC) AS ROW_NUM, "; query += " A.IDGRUPO, "; query += " B.IDMAIL, "; query += " B.MAIL "; query += " FROM "; query += " MAILGRUPOS A, MAILLISTA B "; query += " WHERE A.IDGRUPO=B.IDGRUPO) A "; query += " WHERE "; query += " CAST(A.IDGRUPO AS CHAR) + A.IDMAIL + A.MAIL LIKE '%" + ((String) filterValue).toUpperCase() + "%'"; query += " AND CAST(A.IDGRUPO AS CHAR) = '" + vecidgrupo[0] + "'"; query += " and a.idmail like '" + idmail + "%'"; query += " AND A.instancia = '" + instancia + "'"; query += " AND A.ROW_NUM > " + first; query += " ORDER BY " + sortField; break; } pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Maillista select = new Maillista(); select.setIdgrupo(r.getString(1)); select.setIdmail(r.getString(2)); select.setMail(r.getString(3)); //Agrega la lista list.add(select); } } catch (SQLException e) { e.printStackTrace(); } //Cierra las conecciones pstmt.close(); con.close(); r.close(); }
From source file:org.openbizview.util.Bvt007.java
/** * Leer Datos de nominas para asignar a menucheck * @throws NamingException //from w w w . j a v a 2s . c o m * @throws SQLException * @throws IOException **/ private void selectRep() throws NamingException, SQLException { 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 codrep, codrep||' - '||desrep"; query += " from bvt001"; query += " where instancia = '" + instancia + "'"; query += " order by codrep"; break; case "PostgreSQL": query = " Select codrep, codrep||' - '||desrep"; query += " from bvt001"; query += " where instancia = '" + instancia + "'"; query += " order by codrep"; break; case "Microsoft SQL Server": query = " Select codrep, codrep + ' - ' + desrep"; query += " from bvt001"; query += " where instancia = '" + instancia + "'"; query += " order by codrep"; break; } ////System.out.println(query); pstmt = con.prepareStatement(query); ////System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { String codrep = new String(r.getString(1)); String desrep = new String(r.getString(2)); listRep.put(desrep, codrep); sorted = sortByValues(listRep); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openbizview.util.Bvt007.java
/** * Leer registros en la tabla/*w ww . j a v a 2s . com*/ * @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_codrol == null) { b_codrol = " - "; } if (b_codrol == "") { b_codrol = " - "; } String[] veccodrol = b_codrol.split("\\ - ", -1); switch (productName) { case "Oracle": query = "SELECT count_bvt007('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[0] + "','" + instancia + "') from dual"; break; case "PostgreSQL": query = "SELECT count_bvt007('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[0] + "','" + instancia + "')"; break; case "Microsoft SQL Server": query = "SELECT DBO.count_bvt007('" + ((String) filterValue).toUpperCase() + "','" + veccodrol[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(); }