I'm trying to establish a connection to an Oracle database using BasicDataSource
using DBCP.
I downloaded commons-dbcp-1.4-bin.zip
from here.
There are three jar files on the classpath.
- commons-dbcp-1.4
commons-dbcp-1.4-sources- commons-dbcp-1.4-javadoc
I'm using the following code for the connection to be established.
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.dbcp.BasicDataSource;
public class DatabaseConnection {
private final static BasicDataSource BASIC_DATA_SOURCE = new BasicDataSource();
private final static String SQL = "SELECT * FROM admin WHERE login_id=? AND admin_pwd=?";
static {
BASIC_DATA_SOURCE.setDriverClassName("oracle.jdbc.OracleDriver");
BASIC_DATA_SOURCE.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
BASIC_DATA_SOURCE.setUsername("wagafashiondb");
BASIC_DATA_SOURCE.setPassword("root");
}
private static Connection getConnection() throws SQLException {
return BASIC_DATA_SOURCE.getConnection();
}
public boolean exists(String userName, String password) throws SQLException {
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
boolean exists = false;
try {
connection = getConnection();
ps = connection.prepareStatement(SQL);
ps.setString(1, userName);
ps.setString(2, password);
rs = ps.executeQuery();
exists = rs.next();
} finally {
try {
if (connection != null) {connection.close();}
if (ps != null) {ps.close();}
if (rs != null) {rs.close();}
} catch (SQLException e) {
}
}
return exists;
}
}
It throws the following exception,
javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory
It appears to imply that I'm using a wrong source. What might be the reason for this exception to be caused?