Question

I am having a slight problem with using JDBC tomcat pool. I have properly defined the resource in context.xml, as well as referring to it in web.xml. Now in my Database access method, I would like to somehow get a data source for when a user get something from the database. However, when I type this in:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/testDB");

I get the error message "InitialContext cannot be resolved to a type". What is the problem here?

Était-ce utile?

La solution

Be sure to import InitialContext, it sounds like it is missing to the compiler.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top