Example usage for java.sql DriverManager setLogWriter

List of usage examples for java.sql DriverManager setLogWriter

Introduction

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

Prototype

public static void setLogWriter(java.io.PrintWriter out) 

Source Link

Document

Sets the logging/tracing PrintWriter object that is used by the DriverManager and all drivers.

Usage

From source file:org.apache.cayenne.datasource.DriverDataSource.java

@Override
public void setLogWriter(PrintWriter out) throws SQLException {
    DriverManager.setLogWriter(out);
}

From source file:org.executequery.datasource.SimpleDataSource.java

public void setLogWriter(PrintWriter writer) throws SQLException {

    DriverManager.setLogWriter(writer);
}

From source file:org.sakaiproject.nakamura.lite.storage.jdbc.BaseJDBCStorageClientPool.java

@Override
@Activate/* w w w.  j  a v a 2  s . com*/
@SuppressWarnings(value = {
        "NP_CLOSING_NULL" }, justification = "Invalid report, if this was the case then nothing would work")
public void activate(Map<String, Object> properties) throws ClassNotFoundException {
    this.properties = properties;
    super.activate(properties);

    connectionManager = new ConnectionManager(this);
    timer = new Timer();
    timer.schedule(connectionManager, 30000L, 30000L);

    // this is a default cache used where none has been provided.
    if (LOGGER.isDebugEnabled()) {
        DriverManager.setLogWriter(new PrintWriter(System.err));
    }

    String jdbcDriver = StorageClientUtils.getSetting(properties.get(JDBC_DRIVER), "");
    Class<?> driverClass = this.getClass().getClassLoader().loadClass(jdbcDriver);
    if (driverClass != null) {
        LOGGER.info("Loaded Driver Class {} with classloader {} ", driverClass, driverClass.getClassLoader());
        try {
            Driver d = (Driver) driverClass.newInstance();
            LOGGER.info("Created Driver Instance as {} ", d);
        } catch (InstantiationException e) {
            LOGGER.info("Error Creating Driver {} ", driverClass, e);
        } catch (IllegalAccessException e) {
            LOGGER.info("Error Creating Driver {} ", driverClass, e);
        }
    } else {
        LOGGER.error(
                "Failed to Load the DB Driver {}, unless the driver is available in the core bundle, it probably wont be found.",
                jdbcDriver);
    }
    connectionProperties = getConnectionProperties(properties);
    username = StorageClientUtils.getSetting(properties.get(USERNAME), "");
    password = StorageClientUtils.getSetting(properties.get(PASSWORD), "");
    url = StorageClientUtils.getSetting(properties.get(CONNECTION_URL), "");

    LOGGER.info("Loaded Database Driver {} as {}  ", jdbcDriver, driverClass);
    boolean registered = false;
    for (Enumeration<Driver> ed = DriverManager.getDrivers(); ed.hasMoreElements();) {
        registered = true;
        Driver d = ed.nextElement();
        LOGGER.info("JDBC Driver Registration [{}] [{}] [{}] ",
                new Object[] { d, d.getClass(), d.getClass().getClassLoader() });
    }
    if (!registered) {
        LOGGER.warn(
                "The SQL Driver has no drivers registered, did you ensure that that your Driver started up before this bundle ?");
    }
    JDBCStorageClient client = null;
    try {
        // dont use the pool, we dont want this client to be in the pool.
        client = new JDBCStorageClient(this, properties, getSqlConfig(), getIndexColumns(),
                getIndexColumnsTypes(), getIndexColumnsNames(), false);
        client = checkSchema(client);
        if (client == null) {
            LOGGER.warn("Failed to check Schema, no connection");
        }
    } catch (ClientPoolException e) {
        LOGGER.warn("Failed to check Schema", e);
    } catch (NoSuchAlgorithmException e) {
        LOGGER.warn("Failed to check Schema", e);
    } catch (SQLException e) {
        LOGGER.warn("Failed to check Schema", e);
    } catch (StorageClientException e) {
        LOGGER.warn("Failed to check Schema", e);
    } finally {
        if (client != null) {
            // do not close as this will add the client into the pool.
            client.passivate();
            client.destroy();
        }
    }

}

From source file:org.sakaiproject.nakamura.lite.storage.jdbc.JDBCStorageClientPool.java

@Override
@Activate/*ww  w  .j  a v  a  2 s  .  c o  m*/
@SuppressWarnings(value = {
        "NP_CLOSING_NULL" }, justification = "Invalid report, if this was the case then nothing would work")
public void activate(Map<String, Object> properties) throws ClassNotFoundException {
    this.properties = properties;
    super.activate(properties);

    connectionManager = new ConnectionManager();
    timer = new Timer();
    timer.schedule(connectionManager, 30000L, 30000L);

    sharedCache = new ConcurrentLRUMap<String, CacheHolder>(10000);
    // this is a default cache used where none has been provided.
    defaultStorageManagerCache = new StorageCacheManager() {

        public Map<String, CacheHolder> getContentCache() {
            return sharedCache;
        }

        public Map<String, CacheHolder> getAuthorizableCache() {
            return sharedCache;
        }

        public Map<String, CacheHolder> getAccessControlCache() {
            return sharedCache;
        }
    };
    if (LOGGER.isDebugEnabled()) {
        DriverManager.setLogWriter(new PrintWriter(System.err));
    }

    String jdbcDriver = StorageClientUtils.getSetting(properties.get(JDBC_DRIVER), "");
    Class<?> driverClass = this.getClass().getClassLoader().loadClass(jdbcDriver);
    if (driverClass != null) {
        LOGGER.info("Loaded Driver Class {} with classloader {} ", driverClass, driverClass.getClassLoader());
        try {
            Driver d = (Driver) driverClass.newInstance();
            if (d == null) {
                LOGGER.error("Error creating driver instance, got null from {} ", driverClass);
            } else {
                LOGGER.info("Created Driver Instance as {} ", d);
            }
        } catch (InstantiationException e) {
            LOGGER.info("Error Creating Driver {} ", driverClass, e);
        } catch (IllegalAccessException e) {
            LOGGER.info("Error Creating Driver {} ", driverClass, e);
        }
    } else {
        LOGGER.error(
                "Failed to Load the DB Driver {}, unless the driver is available in the core bundle, it probably wont be found.",
                jdbcDriver);
    }
    connectionProperties = getConnectionProperties(properties);
    username = StorageClientUtils.getSetting(properties.get(USERNAME), "");
    password = StorageClientUtils.getSetting(properties.get(PASSWORD), "");
    url = StorageClientUtils.getSetting(properties.get(CONNECTION_URL), "");

    LOGGER.info("Loaded Database Driver {} as {}  ", jdbcDriver, driverClass);
    boolean registered = false;
    for (Enumeration<Driver> ed = DriverManager.getDrivers(); ed.hasMoreElements();) {
        registered = true;
        Driver d = ed.nextElement();
        LOGGER.info("JDBC Driver Registration [{}] [{}] [{}] ",
                new Object[] { d, d.getClass(), d.getClass().getClassLoader() });
    }
    if (!registered) {
        LOGGER.warn(
                "The SQL Driver has no drivers registered, did you ensure that that your Driver started up before this bundle ?");
    }
    JDBCStorageClient client = null;
    try {
        client = (JDBCStorageClient) getClient();
        if (client == null) {
            LOGGER.warn("Failed to check Schema, no connection");
        }
    } catch (ClientPoolException e) {
        LOGGER.warn("Failed to check Schema", e);
    } finally {
        if (client != null) {
            client.close();
        }
    }

}