I'm checking a java webpage code, actually a Liferay portlet's based website.
I was checking the server-side .java files, and in a DAO pattern file, seeing how the programmer dealt with the DB connections. I'm used to Java SE, where you normally get a Connection object calling to the DriverManager
class, but here, things are pretty different:
initContext = new InitialContext();
envContext = (Context) initContext.lookup("java:/comp/env");
ds = (DataSource) envContext.lookup("jdbc/SSMoracle");
conn = ds.getConnection();
Doing this, the object conn
gets a proper connection to the DB, and it works perfectly. I've never seen how it works though, especially the Context
class.
What does this class do, and why is it used instead of using a class that calls DriverManager
to get the proper connection? I would love to know!