Example usage for java.sql DriverManager registerDriver

List of usage examples for java.sql DriverManager registerDriver

Introduction

In this page you can find the example usage for java.sql DriverManager registerDriver.

Prototype

public static void registerDriver(java.sql.Driver driver) throws SQLException 

Source Link

Document

Registers the given driver with the DriverManager .

Usage

From source file:jp.primecloud.auto.tool.management.db.DBConnector.java

public Connection getConnection() {
    Connection con = null;/*from www.  j a v  a 2  s  .co m*/
    try {
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        con = DriverManager.getConnection(url, userId, password);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return con;
}

From source file:com.xtesoft.xtecuannet.framework.templater.filler.utils.SQLScanner.java

private void loadDriver() {
    try {//w  w w.  jav  a2  s.co  m
        Class myDbDriver = Class.forName(driver);
        DriverManager.registerDriver((Driver) myDbDriver.newInstance());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
        logger.error("Error loading the driver: " + driver, e);
    }
}

From source file:com.bc.fiduceo.db.AbstractDriver.java

@Override
public void open(BasicDataSource dataSource) throws SQLException {
    try {/* w ww  . ja v  a  2s.c om*/
        final java.sql.Driver driverClass = (java.sql.Driver) Class.forName(dataSource.getDriverClassName())
                .newInstance();
        DriverManager.registerDriver(driverClass);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new SQLException(e.getMessage());
    }
    connection = DriverManager.getConnection(dataSource.getUrl(), dataSource.getUsername(),
            dataSource.getPassword());
}

From source file:com.lupinenetwork.commandwhitelister.database.MySQLWhitelistDatabase.java

public MySQLWhitelistDatabase(String url, String username, String password, String primaryTableName,
        Driver driver) throws WhitelistDatabaseException {
    init(url, username, password, primaryTableName);

    try {//from  ww w . j  ava 2 s .  c o  m
        DriverManager.registerDriver(driver);
    } catch (SQLException ex) {
        throw new WhitelistDatabaseException(ex);
    }
}

From source file:net.adrianromero.tpv.forms.AppViewConnection.java

/** Creates a new instance of AppViewConnection */
public AppViewConnection() throws BasicException {

    // Leo la configuracion
    m_config = new AppConfig();
    m_config.load();//from  w  w w  .  j av  a  2  s . c  o  m

    m_s = null;

    // Inicializo la conexion contra la base de datos.
    try {

        ClassLoader cloader = new URLClassLoader(
                new URL[] { new File(getProperty("db.driverlib")).toURI().toURL() });
        DriverManager.registerDriver(new DriverWrapper(
                (Driver) Class.forName(getProperty("db.driver"), true, cloader).newInstance()));

        String sDBUser = getProperty("db.user");
        String sDBPassword = getProperty("db.password");
        if (sDBUser != null && sDBPassword != null && sDBPassword.startsWith("crypt:")) {
            // La clave esta encriptada.
            AltEncrypter cypher = new AltEncrypter("cypherkey" + sDBUser);
            sDBPassword = cypher.decrypt(sDBPassword.substring(6));
        }

        m_s = new Session(getProperty("db.URL"), sDBUser, sDBPassword);

        //            BasicDataSource ds = new BasicDataSource();
        //            ds.setUrl(getProperty("db.URL"));
        //            ds.setUsername(sDBUser);
        //            ds.setPassword(sDBPassword);
        //
        //            m_ds = ds;

    } catch (InstantiationException e) {
        throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), e);
    } catch (IllegalAccessException eIA) {
        throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eIA);
    } catch (MalformedURLException eMURL) {
        throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eMURL);
    } catch (ClassNotFoundException eCNF) {
        throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eCNF);
    } catch (SQLException eSQL) {
        throw new BasicException(AppLocal.getIntString("message.databaseconnectionerror"), eSQL);
    }
}

From source file:it.jnrpe.plugin.CCheckOracle.java

/**
 * Connects to the database/*from  ww  w . j  ava  2s  .  c  om*/
 * @param cl
 * @return
 * @throws SQLException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws ClassNotFoundException
 */
private Connection getConnection(CCommandLine cl)
        throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    DriverManager.registerDriver // load driver
    ((Driver) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());

    m_Logger.debug("GETTING CONNECTION TO " + cl.getOptionValue("db") + "@" + cl.getOptionValue("server"));

    Connection conn = DriverManager
            .getConnection(
                    "jdbc:oracle:thin:@" + cl.getOptionValue("server") + ":" + cl.getOptionValue("port", "1521")
                            + ":" + cl.getOptionValue("db"),
                    cl.getOptionValue("username"), cl.getOptionValue("password"));

    return conn;
}

From source file:com.manydesigns.portofino.database.platforms.GoogleCloudSQLDatabasePlatform.java

public GoogleCloudSQLDatabasePlatform() {
    super(new MySQLDialect(), "jdbc:google:rdbms://<instance-name>/<database>");
    try {//from www. j  av a 2 s .com
        DriverManager.registerDriver((Driver) Class.forName("com.google.cloud.sql.Driver").newInstance());
    } catch (Exception e) {
        logger.debug("The driver to connect to Google Cloud SQL from a non-GAE application was not found", e);
    }
}

From source file:org.pentaho.aggdes.test.util.TestUtils.java

public static void registerDriver(final String jdbcDriverClasspath, final String jdbcDriverClassname)
        throws Exception {
    Driver newDriver;/* ww  w .ja  v a2s  .  c om*/
    if (jdbcDriverClasspath != null && !jdbcDriverClasspath.equals("")) {
        URLClassLoader urlLoader = new URLClassLoader(new URL[] { new URL(jdbcDriverClasspath) });
        Driver d = (Driver) Class.forName(jdbcDriverClassname, true, urlLoader).newInstance();
        newDriver = new DriverShim(d);
    } else {
        newDriver = (Driver) Class.forName(jdbcDriverClassname).newInstance();
    }
    DriverManager.registerDriver(newDriver);
    registeredDrivers.put(jdbcDriverClasspath + ":" + jdbcDriverClassname, newDriver); //$NON-NLS-1$
}

From source file:com.lupinenetwork.commandwhitelister.database.MySQLWhitelistDatabase.java

public MySQLWhitelistDatabase(String url, String username, String password, String primaryTableName)
        throws WhitelistDatabaseException {
    init(url, username, password, primaryTableName);

    try {//ww  w  .  j  av  a2  s  . com
        DriverManager.registerDriver(Constants.getDefaultDriver()); // Default driver
    } catch (SQLException ex) {
        throw new WhitelistDatabaseException(ex);
    }
}

From source file:com.c9.vertx.mods.JdbcProcessor.java

private static boolean setupPool(String address, String driver, String url, String username, String password,
        int minPool, int maxPool, int acquire, String automaticTestTable, int idleConnectionTestPeriod,
        String preferredTestQuery, boolean testConnectionOnCheckin, boolean testConnectionOnCheckout)
        throws Exception {
    if (poolMap.get(address) == null) {
        synchronized (poolMap) {
            if (poolMap.get(address) == null) {
                DriverManager.registerDriver((Driver) Class.forName(driver).newInstance());
                ComboPooledDataSource pool = new ComboPooledDataSource();
                pool.setDriverClass(driver);
                pool.setJdbcUrl(url);/*www.  ja va  2  s  .com*/
                //               pool.setUser(username);
                //               pool.setPassword(password);
                pool.setMinPoolSize(minPool);
                pool.setMaxPoolSize(maxPool);
                pool.setAcquireIncrement(acquire);
                pool.setAutomaticTestTable(automaticTestTable);
                pool.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
                pool.setPreferredTestQuery(preferredTestQuery);
                pool.setTestConnectionOnCheckin(testConnectionOnCheckin);
                pool.setTestConnectionOnCheckout(testConnectionOnCheckout);
                if (poolMap.putIfAbsent(address, pool) != null) {
                    pool.close();
                } else {
                    metrics = new MetricRegistry(String.format("%s.metrics", address));
                    requests = metrics.meter(name(JdbcProcessor.class, "requests"));
                    jmxReporter = JmxReporter.forRegistry(metrics).build();
                    jmxReporter.start();
                    return true;
                }
            }
        }
    }
    return false;
}