1

I am using "com.mchange.v2.c3p0.ComboPooledDataSource" in my standalone java database loader application. Upon initializing data connection it print out connection information to the console windows in eclipse. It also include database username & password related information.

Db used is MariaDB.

"Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@b1a58a3            [connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@7a4f0f29"

How can i prevent it to show this message to the console. The content is print to the console after this line of code

myConn = DataSource.getInstance().getConnection();

Implementation :

public class DataSource {

    private static DataSource datasource;
    private ComboPooledDataSource cpds;
    Properties prop = new Properties();
    InputStream input = null;

    private DataSource() throws IOException, SQLException, PropertyVetoException {

            input = new FileInputStream("config.properties");
            prop.load(input);

            cpds = new ComboPooledDataSource();
            cpds.setDriverClass(prop.getProperty("driverclass")); //loads the jdbc driver
            cpds.setJdbcUrl(prop.getProperty("database"));
            cpds.setUser(prop.getProperty("dbuser"));
            cpds.setPassword(prop.getProperty("dbpassword"));
            cpds.setMinPoolSize(5);
            cpds.setAcquireIncrement(5);
            cpds.setMaxPoolSize(20);
            cpds.setMaxStatements(180);

    }

    public static DataSource getInstance() throws IOException, SQLException, PropertyVetoException {
        if (datasource == null) {
            datasource = new DataSource();
            return datasource;
        } else {
            return datasource;
        }
    }

    public Connection getConnection() throws SQLException {
        return this.cpds.getConnection();
    }

}

I read the config.properties file where i store the database name and crdentials details.

I am calling the connection pool from my main class like this,

myConn = DataSource.getInstance().getConnection();
myConn.setAutoCommit(false);

Soon after this line is executed , i see an entry in the console mentioning details about the connection pool including database name , username and password details. I am not using log4j for connection pooling , it is being used only for application level logging.

Ashesh Nair
  • 317
  • 5
  • 21
  • It is actually helpful to identify the error, as far as the username and password concerns check your code, whether it is printing this information (username and password) using some log statement or Sysout or not – Bilbo Baggins Oct 27 '15 at 05:38
  • Possible duplicate of [how do I turn off logging in java c3p0 connection pooling lib?](http://stackoverflow.com/questions/2976308/how-do-i-turn-off-logging-in-java-c3p0-connection-pooling-lib) – Bohuslav Burghardt Oct 27 '15 at 05:38
  • hi bilbo , thr isnt any sysout statement being executed. It is printing the information soon after getconnection() is being called. – Ashesh Nair Oct 27 '15 at 05:39
  • I tried the solution explained in that thread , but its of no help in my scenario. I have even tried to set logger root level to NONE and even then i can see connection pool information being printed out to the console. – Ashesh Nair Oct 27 '15 at 05:41
  • Any suggestion guys ? – Ashesh Nair Oct 27 '15 at 06:27

0 Answers0