List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.alfresco.hibernate.DialectFactoryBean.java
@SuppressWarnings("deprecation") @Override/*w w w . ja va 2 s . com*/ public Dialect getObject() throws SQLException { Session session = ((SessionFactory) this.localSessionFactory.getObject()).openSession(); Configuration cfg = this.localSessionFactory.getConfiguration(); Connection con = null; try { // make sure that we AUTO-COMMIT con = session.connection(); con.setAutoCommit(true); DatabaseMetaData meta = con.getMetaData(); Dialect dialect = DialectFactory.buildDialect(cfg.getProperties(), meta.getDatabaseProductName(), meta.getDatabaseMajorVersion()); dialect = changeDialect(cfg, dialect); return dialect; } finally { try { con.close(); } catch (Exception e) { } } }
From source file:org.kuali.rice.krad.data.platform.MaxValueIncrementerFactoryTest.java
private void setUpMetaData(DataSource dataSource, String platformName, int version) throws SQLException { DatabaseMetaData metaData = mock(DatabaseMetaData.class); when(metaData.getDatabaseProductName()).thenReturn(platformName); when(metaData.getDatabaseMajorVersion()).thenReturn(version); Connection connection = mock(Connection.class); when(connection.getMetaData()).thenReturn(metaData); when(dataSource.getConnection()).thenReturn(connection); }
From source file:org.kawanfw.test.api.client.SelectInTransationTest.java
/** * @param connection// w w w.j av a 2 s. c o m * the AceQL Connection * * @throws SQLException * @throws Exception */ public void test(Connection connection) throws SQLException, Exception { MessageDisplayer.initClassDisplay(this.getClass().getSimpleName()); if (connection instanceof RemoteConnection) { RemoteConnection connectionHttp = (RemoteConnection) connection; if (connectionHttp.isStatelessMode()) { MessageDisplayer.display("Select in transaction are not supported in stateless mode"); return; } } DatabaseMetaData databaseMetaData = connection.getMetaData(); MessageDisplayer.display( "databaseMetaData.getDatabaseProductName() : " + databaseMetaData.getDatabaseProductName()); // We can now use our Remote JDBC Connection as a regular Connection! connection.setAutoCommit(false); String sql = null; try { sql = "update customer set lname = ? where customer_id = ?"; PreparedStatement prepStatement2 = connection.prepareStatement(sql); prepStatement2.setString(1, "Newname_1"); prepStatement2.setInt(2, 1); int rc = prepStatement2.executeUpdate(); MessageDisplayer.display(""); MessageDisplayer.display("rc: " + rc); sql = "select customer_id, lname from customer where customer_id >= ?"; PreparedStatement prepStatement = connection.prepareStatement(sql); prepStatement.setInt(1, 1); ResultSet rs = prepStatement.executeQuery(); while (rs.next()) { int customerId = rs.getInt("customer_id"); String lname = rs.getString("lname"); System.out.println("customer_id: " + customerId); System.out.println("lname : " + lname); } } catch (Exception e) { connection.rollback(); throw e; } finally { connection.setAutoCommit(true); } MessageDisplayer.display("Done!"); }
From source file:org.rhq.enterprise.server.util.SystemDatabaseInformation.java
private SystemDatabaseInformation() { DataSource ds = null;/*from w w w. j av a 2s. c o m*/ Connection conn = null; try { ds = LookupUtil.getDataSource(); conn = ds.getConnection(); DatabaseMetaData metadata = conn.getMetaData(); String url = metadata.getURL(); String productName = metadata.getDatabaseProductName(); String productVersion = metadata.getDatabaseProductVersion(); String driverName = metadata.getDriverName(); String driverVersion = metadata.getDriverVersion(); Map<Property, String> values = new HashMap<Property, String>(); values.put(Property.DATABASE_CONNECTION_URL, url); values.put(Property.DATABASE_PRODUCT_NAME, productName); values.put(Property.DATABASE_PRODUCT_VERSION, productVersion); values.put(Property.DATABASE_DRIVER_NAME, driverName); values.put(Property.DATABASE_DRIVER_VERSION, driverVersion); values.put(Property.CURRENT_MEASUREMENT_TABLE, MeasurementDataManagerUtility.getCurrentRawTable()); values.put(Property.NEXT_MEASUREMENT_TABLE_ROTATION, MeasurementDataManagerUtility.getNextRotationTime()); properties = Collections.unmodifiableMap(values); } catch (Exception e) { log.error("Could not load properties for " + SystemDatabaseInformation.class.getSimpleName()); } finally { if (properties == null) { Map<Property, String> values = new HashMap<Property, String>(); for (Property prop : Property.values()) { values.put(prop, "unknown"); } properties = Collections.unmodifiableMap(values); } JDBCUtil.safeClose(conn); } }
From source file:org.wso2.carbon.bpel.b4p.coordination.dao.jpa.AbstractJPAVendorAdapter.java
protected DatabaseType determineDbType() { Connection con = null;//from www. j ava2 s. c om DatabaseType dbType = null; try { con = getDBConnection(); DatabaseMetaData metaData = con.getMetaData(); if (metaData != null) { String dbProductName = metaData.getDatabaseProductName().toLowerCase(); int dbMajorVer = metaData.getDatabaseMajorVersion(); if (log.isDebugEnabled()) { log.debug("Using database " + dbProductName + " major version " + dbMajorVer); } if (dbProductName.contains("db2")) { dbType = DatabaseType.DB2; } else if (dbProductName.contains("oracle")) { dbType = DatabaseType.ORACLE; } else if (dbProductName.contains("derby")) { dbType = DatabaseType.DERBY; } else if (dbProductName.contains("h2")) { dbType = DatabaseType.H2; } else if (dbProductName.contains("hsql")) { dbType = DatabaseType.HSQL; } else if (dbProductName.contains("microsoft sql")) { dbType = DatabaseType.SQL_SERVER; } else if (dbProductName.contains("mysql")) { dbType = DatabaseType.MYSQL; } else if (dbProductName.contains("postgresql")) { dbType = DatabaseType.POSTGRESQL; } else if (dbProductName.contains("sybase")) { dbType = DatabaseType.SYBASE; } } } catch (SQLException e) { log.warn("Unable to determine database dialect.", e); } finally { close(con); } return dbType; }
From source file:org.openmrs.module.emrmonitor.api.db.hibernate.HibernateEmrMonitorDAO.java
@Override public Map<String, String> getDatabaseMetadata() { final Map<String, String> ret = new LinkedHashMap<String, String>(); sessionFactory.getCurrentSession().doWork(new Work() { @Override/*from w ww .j a v a2 s. c o m*/ public void execute(Connection connection) throws SQLException { DatabaseMetaData md = connection.getMetaData(); ret.put("product.name", md.getDatabaseProductName()); ret.put("product.version", md.getDatabaseProductVersion()); ret.put("product.majorVersion", Integer.toString(md.getDatabaseMajorVersion())); ret.put("product.minorVersion", Integer.toString(md.getDatabaseMinorVersion())); } }); return ret; }
From source file:org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.AbstractJPAVendorAdapter.java
/** * Determine the data base dialect type based on connection meta-data * @return//from ww w . ja v a2s . co m */ protected DatabaseType determineDbType() { Connection con = null; DatabaseType dbType = null; try { con = getDBConnection(); DatabaseMetaData metaData = con.getMetaData(); if (metaData != null) { String dbProductName = metaData.getDatabaseProductName().toLowerCase(); int dbMajorVer = metaData.getDatabaseMajorVersion(); if (log.isDebugEnabled()) log.debug("Using database " + dbProductName + " major version " + dbMajorVer); if (dbProductName.contains("db2")) { dbType = DatabaseType.DB2; } else if (dbProductName.contains("oracle")) { dbType = DatabaseType.ORACLE; } else if (dbProductName.contains("derby")) { dbType = DatabaseType.DERBY; } else if (dbProductName.contains("h2")) { dbType = DatabaseType.H2; } else if (dbProductName.contains("hsql")) { dbType = DatabaseType.HSQL; } else if (dbProductName.contains("microsoft sql")) { dbType = DatabaseType.SQL_SERVER; } else if (dbProductName.contains("mysql")) { dbType = DatabaseType.MYSQL; } else if (dbProductName.contains("postgresql")) { dbType = DatabaseType.POSTGRESQL; } else if (dbProductName.contains("sybase")) { dbType = DatabaseType.SYBASE; } } } catch (SQLException e) { log.warn("Unable to determine database dialect.", e); } finally { close(con); } return dbType; }
From source file:org.focusns.service.env.impl.EnvironmentServiceImpl.java
protected Environment lookupDB() { try {//www . ja va2 s. c o m DatabaseMetaData metaData = dataSource.getConnection().getMetaData(); // EnvironmentDB envDB = new EnvironmentDB(); envDB.setDatabaseName(metaData.getDatabaseProductName()); envDB.setDatabaseVersion(metaData.getDatabaseProductVersion()); envDB.setDriverName(metaData.getDriverName()); envDB.setDriverVersion(metaData.getDriverVersion()); envDB.setUrl(metaData.getURL()); envDB.setUsername(metaData.getUserName()); envDB.setMaxConnections(metaData.getMaxConnections()); // metaData.getConnection().close(); // return envDB; } catch (SQLException e) { throw new UnsupportedOperationException(e); } }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isHive(DatabaseMetaData metadata) { if (metadata != null) { try {/*www .j a v a 2s . c o m*/ String name = metadata.getDatabaseProductName(); if (name != null && name.equals(EDatabaseTypeName.HIVE.getDisplayName())) { return true; } } catch (SQLException e) { ExceptionHandler.process(e); } } return false; }
From source file:com.mmnaseri.dragonfly.dialect.impl.Mysql5Dialect.java
@Override public boolean accepts(DatabaseMetaData databaseMetaData) { try {/*from w w w . java 2s . c o m*/ return databaseMetaData.getDatabaseProductName().toLowerCase().matches("mysql") && databaseMetaData.getDatabaseMajorVersion() == 5; } catch (SQLException e) { throw new DatabaseMetadataAccessError(e); } }