PrepAway - Latest Free Exam Questions & Answers

which of the following obtains a JDBC data source named MyDataSource?

Assuming variable env is a reference to a hashtable containing the parameters necessary to
obtain the JNDI initial context, which of the following obtains a JDBC data source named
MyDataSource?

PrepAway - Latest Free Exam Questions & Answers

A.
DataSource ds;
try {
ctx = new InitialContext(env);
ds = (DataSource) ctx.getNameInNamespace(“MyDataSource”);
} catch (NamingException ne) { }

B.
DataSource ds;
try {
ctx = new InitialContext(env);
ds = (DataSource) ctx.getURLOrDefaultInitCtx(“MyDataSource”);
} catch (NamingException ne) { }

C.
DataSource ds;
try {
ctx = new InitialContext(env);
ds = (DataSource) ctx.getConnection(“MyDataSource”);
} catch (NamingException ne) { }

D.
DataSource ds;
try {
ctx = new InitialContext(env);
ds = (DataSource) ctx.lookup(“MyDataSource”);
} catch (NamingException ne) { }


Leave a Reply