Context ctx = null;
try {
Properties prop = new Properties();
prop.setProperty(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
prop.setProperty(
Context.PROVIDER_URL,
"file:/JNDI/JDBC");
ctx = new InitialContext(prop);
}
catch (NamingException ne) {
System.err.println(ne.getMessage());
}
DataSource ds = (DataSource)ctx.lookup("joe");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(
"select 'Hello Thin driver data source tester '||" +
"initcap(USER)||'!' result from dual");
if (rset.next())
System.out.println(rset.getString(1));
rset.close();
stmt.close();
conn.close();