List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.openadaptor.auxil.connector.jdbc.writer.AbstractSQLWriter.java
protected void logDBInfo(DatabaseMetaData dmd) throws SQLException { if (debug_db_version_not_logged && log.isDebugEnabled()) { String productName = dmd.getDatabaseProductName(); try {//from w w w . jav a2s .c om log.debug("DB Name (version major/minor): " + productName + " (" + dmd.getDatabaseMajorVersion() + "/" + dmd.getDatabaseMinorVersion() + ")"); } catch (AbstractMethodError ame) { //Sybase jconn2 driver doesn't implement the maj/min methods. log.debug("DB Name: " + productName); } log.debug("DB Version: " + dmd.getDatabaseProductVersion()); debug_db_version_not_logged = false; //Don't report it any more. } }
From source file:com.jaspersoft.jasperserver.war.common.HeartbeatBean.java
private void initHeartbeat() { osName = System.getProperty("os.name"); osVersion = System.getProperty("os.version"); javaVendor = System.getProperty("java.vendor"); javaVersion = System.getProperty("java.version"); serverInfo = servletContext.getServerInfo(); location = servletContext.getRealPath("/"); dbName = null;//from w ww . j ava 2 s . c om dbVersion = null; Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); dbName = metaData.getDatabaseProductName(); dbVersion = metaData.getDatabaseProductVersion(); } catch (SQLException e) { if (log.isDebugEnabled()) log.debug("Getting database metadata failed.", e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { } } } String idSource = //javaVendor + "|" //+ javaVersion + "|" serverInfo + "|" + productName + "|" //+ productVersion + "|" + (location == null ? "" : location); MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { //heartbeat is always silent } if (messageDigest == null) { localId = String.valueOf(idSource.hashCode()); } else { byte[] idBytes = messageDigest.digest(idSource.getBytes()); StringBuffer idBuffer = new StringBuffer(2 * idBytes.length); for (int i = 0; i < idBytes.length; i++) { String hexa = Integer.toHexString(128 + idBytes[i]).toUpperCase(); hexa = ("00" + hexa).substring(hexa.length()); idBuffer.append(hexa); } localId = idBuffer.toString(); } /* */ File localIdFile = getLocalIdFile(); if (localIdFile.exists() && localIdFile.isFile()) { localIdProperties = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(localIdFile); localIdProperties.load(fis); } catch (IOException e) { if (log.isDebugEnabled()) log.debug("Loading heartbeat local ID properties file failed.", e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } } heartbeatId = localIdProperties.getProperty(PROPERTY_HEARTBEAT_ID); /* */ File clientInfoCacheFile = getClientInfoCacheFile(); if (clientInfoCacheFile.exists() && clientInfoCacheFile.isFile()) { try { clientInfoCache = (HeartbeatInfoCache) JRLoader.loadObject(clientInfoCacheFile); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Loading heartbeat cache from serialized file failed.", e); } } lastCacheSaveTime = System.currentTimeMillis(); }
From source file:org.enlacerh.util.Pnt004.java
/** * Leer Datos de ciudades//from ww w.j a v a 2 s . c o 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 (p_codpai == null) { p_codpai = " - "; } if (p_codpai == "") { p_codpai = " - "; } String[] vecValores = p_codpai.split("\\ - ", -1); switch (productName) { case "Oracle": //Consulta paginada query = " select * from "; query += " ( select query.*, rownum as rn from"; query += " ( SELECT a.codciu, trim(a.desciu), trim(a.estado), b.codpai, trim(b.despai), a.grupo"; query += " FROM Pnt004 a, Pnt003 b"; query += " where a.p_codpai=b.codpai"; query += " and a.grupo=b.grupo"; query += " and a.codciu like '" + codciu.toUpperCase() + "%'"; query += " and a.p_codpai like '%" + vecValores[0] + "%'"; query += " and a.codciu||a.desciu like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and a.grupo = '" + grupo + "'"; query += " order by " + sortField.replace("v", "") + ") query"; query += " ) where rownum <= " + pageSize; query += " and rn > (" + first + ")"; break; case "PostgreSQL": //Consulta paginada query = "SELECT a.codciu, trim(a.desciu), trim(a.estado), b.codpai, trim(b.despai), a.grupo"; query += " FROM Pnt004 a, Pnt003 b"; query += " where a.p_codpai=b.codpai"; query += " and a.grupo=b.grupo"; query += " and CAST(a.codciu AS text) like '" + codciu.toUpperCase() + "%'"; query += " and cast(a.p_codpai AS text) like '%" + vecValores[0] + "%'"; query += " and cast(a.codciu AS text)||a.desciu like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and CAST(a.grupo AS text) = '" + grupo + "'"; query += " order by " + sortField.replace("v", ""); query += " LIMIT " + pageSize; query += " OFFSET " + first; break; } pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Ciudades ciudad = new Ciudades(); ciudad.setVcodciu(r.getString(1)); ciudad.setVdesciu(r.getString(2)); ciudad.setVestado(r.getString(3)); ciudad.setVp_pcodpai(r.getString(4)); ciudad.setVcodpaidespai(r.getString(4) + " - " + r.getString(5)); ciudad.setVgrupo(r.getString(6)); //Agrega la lista list.add(ciudad); } //Cierra las conecciones pstmt.close(); con.close(); r.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openbizview.util.Bvt007.java
/** * Leer Datos de categoria2//w w w. j a v a 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 String query = ""; //System.out.println("b_codrol = "+b_codrol); if (b_codrol == null) { b_codrol = " - "; } if (b_codrol.equals("")) { b_codrol = " - "; } String[] veccodrol = b_codrol.split("\\ - ", -1); switch (productName) { case "Oracle": query += " select * from "; query += " ( select query.*, rownum as rn from"; query += " (SELECT trim(a.b_codrol), trim(b.desrol), trim(a.b_codrep), trim(c.desrep)"; query += " FROM Bvt007 a, bvt003 b, bvt001 c"; query += " WHERE a.b_codrol=b.codrol"; query += " and a.b_codrep=c.codrep "; query += " and A.instancia=B.instancia"; query += " and a.b_codrol||b.desrol||a.b_codrep||c.desrep like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and a.b_codrol like '" + veccodrol[0] + "%'"; query += " AND a.instancia = '" + instancia + "'"; query += " order by " + sortField + ") query"; query += " ) where rownum <= " + pageSize; query += " and rn > (" + first + ")"; break; case "PostgreSQL": query += " SELECT trim(a.b_codrol), trim(b.desrol), trim(a.b_codrep), trim(c.desrep)"; query += " FROM Bvt007 a, bvt003 b, bvt001 c"; query += " WHERE a.b_codrol=b.codrol"; query += " and a.b_codrep=c.codrep "; query += " and A.instancia=B.instancia"; query += " and a.b_codrol||b.desrol||a.b_codrep||c.desrep like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and a.b_codrol like '" + veccodrol[0] + "%'"; query += " AND a.instancia = '" + instancia + "'"; 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_CODREP, "; query += " TOT.DESREP "; 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_CODREP, "; query += " C.DESREP "; query += " FROM BVT007 A, BVT003 B, BVT001 C "; query += " WHERE "; query += " A.B_CODROL = B.CODROL "; query += " AND A.B_CODREP=C.CODREP "; query += " AND A.B_CODROL + B.DESROL + A.B_CODREP + C.DESREP LIKE '%" + ((String) filterValue).toUpperCase() + "%'"; query += " AND A.B_CODROL LIKE '" + veccodrol[0] + "%') TOT "; query += " AND a.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()) { Bvt007 select = new Bvt007(); select.setB_codrol(r.getString(1)); select.setDesrol(r.getString(2)); select.setB_codrep(r.getString(3)); select.setDesrep(r.getString(4)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openbizview.util.Sgc007.java
/** * Leer Datos de paises//w w 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 (coduser == null) { coduser = " - "; } if (coduser == "") { coduser = " - "; } if (comp == null) { comp = " - "; } if (comp == "") { comp = " - "; } String[] veccomp = comp.split("\\ - ", -1); String[] veccodu = coduser.split("\\ - ", -1); //Consulta paginada String query = "SELECT * FROM"; query += "(select query.*, rownum as rn from"; query += "(SELECT TRIM(A.CODUSER) AS CODUSER, A.COMP, B.DESCR AS DESC1 "; query += " FROM SGC007 A, SGC005 B "; query += " WHERE A.COMP = B.CODIGO "; query += " AND TRIM(A.CODUSER) LIKE TRIM('%" + veccodu[0] + "%')"; query += " AND TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%')"; query += " GROUP BY A.CODUSER, A.COMP, B.DESCR"; query += ")query ) "; query += " WHERE ROWNUM <=" + pageSize; query += " AND rn > (" + first + ")"; query += " ORDER BY " + sortField.replace("z", ""); pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Sgc007 select = new Sgc007(); select.setZcomp(r.getString(2) + " - " + r.getString(3)); select.setZcoduser(r.getString(1)); select.setZvaldel(r.getString(1) + "" + r.getString(2)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openbizview.util.Bvt001.java
/** * Leer registros en la tabla/*from w ww. ja v a 2 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 if (codgrup == null) { codgrup = " - "; } if (codgrup == "") { codgrup = " - "; } String[] veccodgrup = codgrup.split("\\ - ", -1); String query = ""; switch (productName) { case "Oracle": query = "SELECT count_bvt001('" + ((String) filterValue).toUpperCase() + "','" + login.toUpperCase() + "','" + veccodgrup[0] + "','" + instancia + "') from dual"; break; case "PostgreSQL": query = "SELECT count_bvt001('" + ((String) filterValue).toUpperCase() + "','" + vlRol + "','" + veccodgrup[0] + "','" + instancia + "')"; break; case "Microsoft SQL Server": query = "SELECT DBO.COUNT_BVT001('" + ((String) filterValue).toUpperCase() + "','" + vlRol + "','" + veccodgrup[0] + "','" + instancia + "')"; } 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.Indh07.java
/** * Leer Datos de paises//from ww w. ja v a2s . 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.totpes, B.DESCIA, C.DESUBI, TO_CHAR(D.FECINI,'DD/MM/YY') AS FECINI, TO_CHAR(D.FECFIN,'DD/MM/YY') AS FECFIN "; query += " FROM INDH07 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, 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()) { Indh07 select = new Indh07(); 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.setZdesc1(r.getString(6)); select.setZdesc2(r.getString(7)); select.setZciadesc(r.getString(1) + " - " + r.getString(6)); select.setZubidesc(r.getString(2) + " - " + r.getString(7)); select.setZsemana(r.getString(4) + " - " + r.getString(8) + " al " + r.getString(9)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openadaptor.auxil.connector.jdbc.writer.AbstractSQLWriter.java
/** * Initialise the writer.//from www . j ava 2s . c om * Determines if batch handling is supported by the database. * */ public void initialise(Connection connection) throws ConnectionException { log.info("Initialising writer"); try { this.connection = connection; DatabaseMetaData dmd = connection.getMetaData(); logDBInfo(dmd); //Need to know vendor for a few quirks. String dbVendorName = dmd.getDatabaseProductName().toLowerCase(); //Initialise table and column name quoting mechanism. if (quoteIdentifiers) { initialiseQuoting(dbVendorName); } if ((oraclePackage != null) && (dbVendorName.indexOf("oracle") < 0)) { log.warn("Oracle package specified, but db vendor is not Oracle. It will be ignored"); oraclePackage = null; } batchSupport = checkBatchSupport(); log.info("Writer does " + (batchSupport ? "" : "NOT ") + "have batch support"); initialiseReusablePreparedStatement(); if ((reusablePreparedStatement != null) && (argSqlTypes == null)) { //Subclass didn't setup the argument types! String msg = "Argument types not set for PreparedStatement calls. This may not work with null values!"; log.warn(msg); } } catch (SQLException e) { throw new ConnectionException("Failed to initialise" + e.toString(), e); } }
From source file:com.atlassian.jira.startup.JiraSystemInfo.java
/** * Obtains database configuration information. This should be called after the database has been checked for sanity * and hence we can safely do some entityengine.xml and database connection test. But this is before the database is * auto-created and hence the support team can get valuable configuration information before a real DB cockup is * encountered.//from w w w .j av a 2s .c o m */ public void obtainDatabaseConfigurationInfo() { logMsg.outputHeader("Database Configuration"); final URL entityEngineURL = ClassLoaderUtils.getResource("entityengine.xml", getClass()); logMsg.outputProperty("Loading entityengine.xml from", entityEngineURL.toString()); final DatasourceInfo datasourceInfo = connectionFactory.getDatasourceInfo(); if (datasourceInfo != null) { logMsg.outputProperty("Entity model field type name", datasourceInfo.getFieldTypeName()); logMsg.outputProperty("Entity model schema name", datasourceInfo.getSchemaName()); } Connection connection = null; try { connection = connectionFactory.getConnection(); final DatabaseMetaData metaData = connection.getMetaData(); final SystemInfoUtils jiraSysInfo = new SystemInfoUtilsImpl(); logMsg.outputProperty("Database Version", metaData.getDatabaseProductName() + " - " + metaData.getDatabaseProductVersion()); logMsg.outputProperty("Database Driver", metaData.getDriverName() + " - " + metaData.getDriverVersion()); logMsg.outputProperty("Database URL", maskURL(metaData.getURL())); logMsg.outputProperty(jiraSysInfo.getDbDescriptorLabel(), jiraSysInfo.getDbDescriptorValue()); } catch (final SQLException e) { // dont worry about this exception here. Code later one will barf on the same problem and do more appropriate actions. // We are just trying to get startup information for support purposes for now. log.debug(e); } finally { silentlyClose(connection); } }
From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java
/** * //ww w. j a v a2 s. co m */ public JRJdbcQueryExecuter(JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters) { super(jasperReportsContext, dataset, parameters); connection = (Connection) getParameterValue(JRParameter.REPORT_CONNECTION); if (connection == null) { if (log.isWarnEnabled()) { log.warn("The supplied java.sql.Connection object is null."); } } else if (log.isDebugEnabled()) { try { DatabaseMetaData metaData = connection.getMetaData(); log.debug("DB is " + metaData.getDatabaseProductName() + " version " + metaData.getDatabaseProductVersion() + " (" + metaData.getDatabaseMajorVersion() + "/" + metaData.getDatabaseMinorVersion() + ")"); log.debug("driver is " + metaData.getDriverName() + " version " + metaData.getDriverVersion() + " (" + metaData.getDriverMajorVersion() + "/" + metaData.getDriverMinorVersion() + ")"); log.debug("jdbc " + metaData.getJDBCMajorVersion() + "/" + metaData.getJDBCMinorVersion()); log.debug("connection URL is " + metaData.getURL()); } catch (SQLException e) { log.debug("failed to read connection metadata", e); } } isCachedRowSet = getBooleanParameterOrProperty(JRJdbcQueryExecuterFactory.PROPERTY_CACHED_ROWSET, false); setTimeZone(); registerFunctions(); parseQuery(); }