Home i can't make connection pool using dbcp
Reply: 0

i can't make connection pool using dbcp

user1872 Published in April 26, 2018, 9:02 pm

i'm trying to make connectionpool,but when i try to run that code
i get an exception,here is my code

import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.commons.dbcp2.BasicDataSource;

public class ConnectionPool {
private static ConnectionPool datasource;
private static BasicDataSource ds=new BasicDataSource();
private ConnectionPool(){
  public static ConnectionPool getInstance(){
       datasource=new ConnectionPool();
   return datasource;
public Connection getConnection() throws SQLException{
   return ds.getConnection();

but when i run that code,i got exception at the decleration of BasicDataSource
the exception is:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/pool2/PooledObjectFactory
    at ConnectionPool.<clinit>(ConnectionPool.java:22)
    at example.main(example.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.PooledObjectFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more
C:\Users\eldee\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

so what should i do?? what is the wrong with my code?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309544 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO