2

I'm having the same problem as the user here: log4j type GenericObjectPool does not take parameters but I've been unable to find an answer to this problem. Log4j2 works when appending to a rollingfile but the method listed here : https://logging.apache.org/log4j/2.x/manual/appenders.html gives me the error "GenericObjectPool does not take Parameters"

package database;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.DriverManagerConnectionFactory;
import org.apache.commons.dbcp.PoolableConnection;
import org.apache.commons.dbcp.PoolableConnectionFactory;
import org.apache.commons.dbcp.PoolingDataSource;
import org.apache.commons.pool.impl.GenericObjectPool;

public class ConnectionFactory {
 private static interface Singleton {
  final ConnectionFactory INSTANCE = new ConnectionFactory();
 }

 private final DataSource dataSource;

 private ConnectionFactory() {
  Properties properties = new Properties();
  properties.setProperty("user", "root");
  properties.setProperty("password", "tiger");

        GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>();
        DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
    "jdbc:mysql://127.0.0.1/logging", properties);
  new PoolableConnectionFactory(connectionFactory, pool, null,
    "SELECT 1",3, false, false,
    Connection.TRANSACTION_READ_COMMITTED
  );

  this.dataSource = new PoolingDataSource(pool);
 }

 public static Connection getDatabaseConnection() throws SQLException {
  return Singleton.INSTANCE.dataSource.getConnection();
 }
}
1
  • same problem, any solution? Commented May 31, 2017 at 20:53

1 Answer 1

0

Issue has been resolved by myself.

I have added maven dependency it working fine for me.

<dependency>
    <groupId>commons-pool</groupId>
    <artifactId>commons-pool</artifactId>
    <version>1.6</version>
</dependency>
Sign up to request clarification or add additional context in comments.

1 Comment

Very well, can you accept your answer by checking the checlmark () next to the answer please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.