List of usage examples for java.sql Driver getMajorVersion
int getMajorVersion();
From source file:Main.java
public static void main(String[] argv) throws Exception { List drivers = Collections.list(DriverManager.getDrivers()); for (int i = 0; i < drivers.size(); i++) { Driver driver = (Driver) drivers.get(i); String name = driver.getClass().getName(); System.out.println(name); int majorVersion = driver.getMajorVersion(); System.out.println(majorVersion); int minorVersion = driver.getMinorVersion(); System.out.println(minorVersion); boolean isJdbcCompliant = driver.jdbcCompliant(); System.out.println(isJdbcCompliant); }//from w ww . j av a 2 s . co m }
From source file:Main.java
public static void main(String[] args) throws Exception { Driver myDriver = new org.hsqldb.jdbcDriver(); DriverManager.registerDriver(myDriver); System.out.println(myDriver.acceptsURL("jdbc:mydriver://tutorial/")); System.out.println("Major Version: " + myDriver.getMajorVersion()); System.out.println("Minor Version: " + myDriver.getMinorVersion()); System.out.println("JDBC COMPLIANT driver? " + myDriver.jdbcCompliant()); }
From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java
@Override public RepositoryDiag getRepositoryDiag() { LOGGER.debug("Getting repository diagnostics."); RepositoryDiag diag = new RepositoryDiag(); diag.setImplementationShortName(IMPLEMENTATION_SHORT_NAME); diag.setImplementationDescription(IMPLEMENTATION_DESCRIPTION); SqlRepositoryConfiguration config = getConfiguration(); //todo improve, find and use real values (which are used by sessionFactory) MID-1219 diag.setDriverShortName(config.getDriverClassName()); diag.setRepositoryUrl(config.getJdbcUrl()); diag.setEmbedded(config.isEmbedded()); Enumeration<Driver> drivers = DriverManager.getDrivers(); while ((drivers != null && drivers.hasMoreElements())) { Driver driver = drivers.nextElement(); if (!driver.getClass().getName().equals(config.getDriverClassName())) { continue; }/* w w w. j a va 2s .co m*/ diag.setDriverVersion(driver.getMajorVersion() + "." + driver.getMinorVersion()); } List<LabeledString> details = new ArrayList<>(); diag.setAdditionalDetails(details); details.add(new LabeledString(DETAILS_DATA_SOURCE, config.getDataSource())); details.add(new LabeledString(DETAILS_HIBERNATE_DIALECT, config.getHibernateDialect())); details.add(new LabeledString(DETAILS_HIBERNATE_HBM_2_DDL, config.getHibernateHbm2ddl())); readDetailsFromConnection(diag, config); Collections.sort(details, new Comparator<LabeledString>() { @Override public int compare(LabeledString o1, LabeledString o2) { return String.CASE_INSENSITIVE_ORDER.compare(o1.getLabel(), o2.getLabel()); } }); return diag; }
From source file:ch.rgw.tools.JdbcLink.java
/** * Verbindung zur Datenbank herstellen/*from ww w . j a v a 2 s . c o m*/ * * TODO return value is always true because exception is thrown on error * * @param user * Username, kann null sein * @param password * Passwort, kann null sein * @return errcode * * @throws JdbcLinkException */ public boolean connect(String user, String password) { Exception cause = null; try { sUser = user; sPwd = password; Driver driver = (Driver) Class.forName(sDrv).newInstance(); verMajor = driver.getMajorVersion(); verMinor = driver.getMinorVersion(); log.log(Level.INFO, "Loading database driver " + sDrv); log.log(Level.INFO, "Connecting with database " + sConn); // // First, we'll create a ConnectionFactory that the // pool will use to create Connections. // Properties properties = new Properties(); properties.put("user", user); properties.put("password", password); ConnectionFactory connectionFactory = new DriverConnectionFactory(driver, sConn, properties); // // Next we'll create the PoolableConnectionFactory, which wraps // the "real" Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. // connectionPool = new GenericObjectPool<Connection>(null); // configure the connection pool connectionPool.setMaxActive(32); connectionPool.setMinIdle(2); connectionPool.setMaxWait(10000); connectionPool.setTestOnBorrow(true); new PoolableConnectionFactory(connectionFactory, connectionPool, null, VALIDATION_QUERY, false, true); dataSource = new PoolingDataSource(connectionPool); // test establishing a connection Connection conn = dataSource.getConnection(); conn.close(); lastErrorCode = CONNECT_SUCCESS; lastErrorString = "Connect successful"; log.log("Connect successful", Log.DEBUGMSG); return true; } catch (ClassNotFoundException ex) { lastErrorCode = CONNECT_CLASSNOTFOUND; lastErrorString = "Class not found exception: " + ex.getMessage(); cause = ex; } catch (InstantiationException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Instantiation exception: " + e.getMessage(); cause = e; } catch (IllegalAccessException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Illegal access exception: " + e.getMessage(); cause = e; } catch (SQLException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "SQL exception: " + e.getMessage(); cause = e; } catch (IllegalStateException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Illegal state exception: " + e.getMessage(); cause = e; } throw JdbcLinkExceptionTranslation.translateException("Connect failed: " + lastErrorString, cause); }
From source file:org.rimudb.editor.RimuDBEditor.java
protected void driverCheck() { driverMap = getPreferences().getDrivers(); if (driverMap != null) { Set<String> keyset = driverMap.keySet(); for (String driverName : keyset) { DriverEntry driverEntry = driverMap.get(driverName); boolean found = false; try { Class.forName(driverEntry.getJdbcDriver()); found = true;/*from ww w . jav a 2s .c om*/ } catch (Exception e) { log.info("driverCheck() Could not find driverClass", e); } driverEntry.setFound(found); } List<Driver> drivers = Collections.list(DriverManager.getDrivers()); for (int i = 0; i < drivers.size(); i++) { Driver driver = (Driver) drivers.get(i); // Find the driver in the map and add the version to the DriverEntry Collection<DriverEntry> values = driverMap.values(); for (DriverEntry driverEntry : values) { if (driverEntry.getJdbcDriver().trim().equals(driver.getClass().getName())) { driverEntry.setDriverVersion(driver.getMajorVersion() + "." + driver.getMinorVersion()); } } } } }