List of usage examples for java.sql Driver getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
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 w w . ja v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("org.gjt.mm.mysql.Driver"); Properties info = new Properties(); Driver driver = DriverManager.getDriver("jdbc:mysql://localhost/demo2s"); System.out.println("driver=" + driver); DriverPropertyInfo[] attributes = driver.getPropertyInfo("jdbc:mysql://localhost/demo2s", info); System.out.println("attributes=" + attributes); // zero length means a connection attempt can be made System.out.println("Resolving properties for: " + driver.getClass().getName()); for (int i = 0; i < attributes.length; i++) { // get the property metadata String name = attributes[i].name; String[] choices = attributes[i].choices; boolean required = attributes[i].required; String description = attributes[i].description; // printout property metadata System.out.println(name + " (Required: " + required + ")"); if (choices == null) { System.out.println(" No choices."); } else {//from ww w . j av a2 s . com System.out.print(" Choices are: "); for (int j = 0; j < choices.length; j++) { System.out.print(" " + choices[j]); } } System.out.println(" Description: " + description); } }
From source file:com.ironiacorp.persistence.SqlUtil.java
/** * Check if the database driver is loaded. * /* w ww .j a v a 2 s . co m*/ * @return True if the driver is loaded, False otherwise. */ public static boolean isDriverLoaded(String driver) { // Check if the driver has been already loaded Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver d = drivers.nextElement(); if (d.getClass().getName().equals(driver)) { return true; } } return false; }
From source file:com.ironiacorp.persistence.SqlUtil.java
/** * Unload the database driver (if it's loaded). *//*from w ww. j a va 2 s. c o m*/ public static void unloadDriver(String driver) { if (!SqlUtil.isDriverLoaded(driver)) { return; } Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver d = drivers.nextElement(); if (d.getClass().getName().equals(driver)) { try { DriverManager.deregisterDriver(d); } catch (SQLException e) { } } } }
From source file:com.jt.dbcp.example.ManualPoolingDataSourceExample.java
public static void printDataSourceStats(DataSource ds) { Enumeration<Driver> driver = DriverManager.getDrivers(); while (driver.hasMoreElements()) { Driver d = driver.nextElement(); System.out.println(d.getClass()); }//from w w w.j av a2 s .com }
From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.TibcoDriverManagerImpl.java
static boolean isDriverExisted(String driverClass) { Enumeration<Driver> e = DriverManager.getDrivers(); while (e.hasMoreElements()) { Driver driver = (Driver) e.nextElement(); String driverClassName = (String) driver.getClass().getName(); if (driverClassName.equals(driverClass)) return true; }/*www . ja v a2 s. c o m*/ return false; }
From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.TibcoDriverManagerImpl.java
static void deregisterTibcosoftwareincDrivers() { Enumeration<Driver> e = DriverManager.getDrivers(); while (e.hasMoreElements()) { Driver driver = (Driver) e.nextElement(); String driverClassName = (String) driver.getClass().getName(); try {/*from w w w. ja v a2 s. c om*/ if (driverClassName.startsWith("tibcosoftwareinc.")) DriverManager.deregisterDriver(driver); } catch (Exception ex) { printLog("Unable to deregister driver: " + driverClassName, ex); } } }
From source file:com.mg.jet.birt.report.data.oda.ejbql.HibernateUtil.java
private static synchronized void initSessionFactory(String hibfile, String mapdir, String jndiName) throws HibernateException { //ClassLoader cl1; if (sessionFactory == null) { if (jndiName == null || jndiName.trim().length() == 0) jndiName = CommonConstant.DEFAULT_JNDI_URL; Context initCtx = null;/* ww w . j a v a 2 s. c om*/ try { initCtx = new InitialContext(); sessionFactory = (SessionFactory) initCtx.lookup(jndiName); return; } catch (Exception e) { logger.log(Level.INFO, "Unable to get JNDI data source connection", e); } finally { if (initCtx != null) try { initCtx.close(); } catch (NamingException e) { //ignore } } Thread thread = Thread.currentThread(); try { //Class.forName("org.hibernate.Configuration"); //Configuration ffff = new Configuration(); //Class.forName("org.apache.commons.logging.LogFactory"); oldloader = thread.getContextClassLoader(); //Class thwy = oldloader.loadClass("org.hibernate.cfg.Configuration"); //Class thwy2 = oldloader.loadClass("org.apache.commons.logging.LogFactory"); //refreshURLs(); //ClassLoader changeLoader = new URLClassLoader( (URL [])URLList.toArray(new URL[0]),HibernateUtil.class.getClassLoader()); ClassLoader testLoader = new URLClassLoader((URL[]) URLList.toArray(new URL[0]), pluginLoader); //changeLoader = new URLClassLoader( (URL [])URLList.toArray(new URL[0])); thread.setContextClassLoader(testLoader); //Class thwy2 = changeLoader.loadClass("org.hibernate.cfg.Configuration"); //Class.forName("org.apache.commons.logging.LogFactory", true, changeLoader); //Class cls = Class.forName("org.hibernate.cfg.Configuration", true, changeLoader); //Configuration cfg=null; //cfg = new Configuration(); //Object oo = cls.newInstance(); //Configuration cfg = (Configuration)oo; Configuration cfg = new Configuration(); buildConfig(hibfile, mapdir, cfg); Class<? extends Driver> driverClass = testLoader .loadClass(cfg.getProperty("connection.driver_class")).asSubclass(Driver.class); Driver driver = driverClass.newInstance(); WrappedDriver wd = new WrappedDriver(driver, cfg.getProperty("connection.driver_class")); boolean foundDriver = false; Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver nextDriver = (Driver) drivers.nextElement(); if (nextDriver.getClass() == wd.getClass()) { if (nextDriver.toString().equals(wd.toString())) { foundDriver = true; break; } } } if (!foundDriver) { DriverManager.registerDriver(wd); } sessionFactory = cfg.buildSessionFactory(); //configuration = cfg; HibernateMapDirectory = mapdir; HibernateConfigFile = hibfile; } catch (Throwable e) { e.printStackTrace(); throw new HibernateException("No Session Factory Created " + e.getLocalizedMessage(), e); } finally { thread.setContextClassLoader(oldloader); } } }
From source file:com.flexive.core.Database.java
/** * Cleanup cached data sources.//from w ww . ja v a2 s .co m * * @since 3.1.4 */ public static synchronized void cleanup() { if (defaultDataSourceInitialized) { // try to deregister bundled H2 driver try { final Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { final Driver driver = drivers.nextElement(); if ("org.h2.Driver".equals(driver.getClass().getCanonicalName())) { // deregister our bundled H2 driver LOG.info("Uninstalling bundled H2 driver"); DriverManager.deregisterDriver(driver); } } } catch (Exception e) { LOG.warn("Failed to deregister H2 driver", e); } } dataSourcesByName.clear(); for (int i = 0; i < dataSources.length; i++) { dataSources[i] = null; } for (int i = 0; i < dataSourcesNoTX.length; i++) { dataSourcesNoTX[i] = null; } globalDataSource = null; testDataSource = null; testDataSourceNoTX = null; }
From source file:com.wavemaker.runtime.server.CleanupListener.java
@Override public void contextDestroyed(ServletContextEvent event) { try {/*from w w w. jav a2s .c o m*/ // remove from the system DriverManager the JDBC drivers registered // by this web app for (Enumeration<Driver> e = CastUtils.cast(DriverManager.getDrivers()); e.hasMoreElements();) { Driver driver = e.nextElement(); if (driver.getClass().getClassLoader() == getClass().getClassLoader()) { DriverManager.deregisterDriver(driver); } } LogFactory.releaseAll(); // flush all of the Introspector's internal caches Introspector.flushCaches(); } catch (Exception e) { e.printStackTrace(); } }