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

i can't make connection pool using dbcp

Shraf Eldeen
1#
Shraf Eldeen Published in 2017-12-07 22:01:00Z

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(){
    ds.setDriverClassName("com.mysql.jdbc.driver");
    ds.setUsername("root");
    ds.setPassword("36445236");
    ds.setUrl("jdbc:mysql://localhost:3306/?user=root");
}
  public static ConnectionPool getInstance(){
   if(datasource==null)
       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:

run:
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.304881 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO