Question

Using this post I want to create JUnit test with datasource. I tested this code:

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.activation.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.junit.BeforeClass;

public class NewEmptyJUnitTest
{

    public NewEmptyJUnitTest()
    {
    }

    @BeforeClass
    public static void setUpClass() throws Exception
    {
        // rcarver - setup the jndi context and the datasource
        try
        {
            // Create initial context
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.naming.java.javaURLContextFactory");
            System.setProperty(Context.URL_PKG_PREFIXES,
                    "org.apache.naming");
            InitialContext ic = new InitialContext();

            ic.createSubcontext("java:");
            ic.createSubcontext("java:/comp");
            ic.createSubcontext("java:/comp/env");
            ic.createSubcontext("java:/comp/env/jdbc");

            // Construct DataSource
            OracleConnectionPoolDataSource ds = new OracleConnectionPoolDataSource();
            ds.setURL("jdbc:oracle:thin:@host:port:db");
            ds.setUser("MY_USER_NAME");
            ds.setPassword("MY_USER_PASSWORD");

            ic.bind("java:/comp/env/jdbc/nameofmyjdbcresource", ds);
        }
        catch (NamingException ex)
        {
            Logger.getLogger(MyDAOTest.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void inittest() throws NamingException
    {

        Context initContext = new InitialContext();
        Context webContext = (Context) initContext.lookup("java:/comp/env");

        DataSource ds = (DataSource) webContext.lookup("jdbc/nameofmyjdbcresource");

    }
}

But Netbeans cannot find this class 'OracleConnectionPoolDataSource'. How I can solve this problem? What is the package that I have to import in order to use this class?

Was it helpful?

Solution

As per ojdbc14.jar, OracleConnectionPoolDataSource can be found in oracle.jdbc.pool:

import oracle.jdbc.pool.OracleConnectionPoolDataSource;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top