I am 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 in the classpath.
- ordinary-DBHP-1,4
Commons-DBCD-1.4-Sources- Ordinary-DBHP-1,4-Javadoc
I am using the following code to establish a connection.
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 looks like I'm using the wrong source. What could be the reason for this exception?
source share