1

I'm getting "While trying to lookup 'jdbc.LogDB' didn't find subcontext 'jdbc'. Resolved ''" error when i try to get connection from the Weblogic. I created and tested the datasource and it's working. Also created the target servers. Datasource name is "jdbc/LogDb". Below is the test code i wrote.

public class TestUtils {
    private static final Logger logger = LoggerFactory.getLogger(TestUtils.class.getName());
    public DataSource ds = null;
    public String testConnectionPool()  throws SQLException {
        Context ctx = null;
        Hashtable ht = new Hashtable();
        Connection conn;
        String result = "";

        ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
        ht.put(Context.SECURITY_PRINCIPAL, "weblogic");
        ht.put(Context.SECURITY_CREDENTIALS, "weblogic");


        try {
            ctx = new InitialContext(ht);
            ds = (DataSource) ctx.lookup("jdbc/LogDB");
            logger.debug("Weblogic Connection Pool Created");



        conn = ds.getConnection();
        Statement stmt = conn.createStatement();
        stmt.execute("some sql");
        ResultSet rs = stmt.getResultSet();

        if(rs.next()){
            result = result + rs.getString(1);
        }
        stmt.close();
        conn.close();
        } catch (NamingException e) {
            logger.error("Naming Exception occured at connect: " + e.getMessage());
        } catch (Exception e){
            logger.error("Exception occured at connect: "+ e.getMessage());
        } finally {
            try {
                if (ctx != null) {
                    ctx.close();
                }
            }
            catch (Exception e) {
                logger.error("Ctx Error");
            }
        }
       return result;
    }
}

I tried the following names "java:jdbc/LogDb" "java:comp/env" variations etc.

Thanks for the kind answers

Jerodev
  • 32,252
  • 11
  • 87
  • 108
user3755508
  • 73
  • 1
  • 1
  • 4
  • In weblogic your datasource's JNDI value is `jdbc/LogDB`? If you log in to the admin console, click your server name, and then click the "View JNDI tree" link, do you see the datasource there? – Display Name is missing Oct 13 '14 at 17:42
  • Yes value is jdbc/LogDB – user3755508 Oct 14 '14 at 06:22
  • The problem corrected itself after i restarted the application servers. You have to restart weblogic and applications servers in order to connect the new created jndi source. Thanks – user3755508 Oct 14 '14 at 10:46

0 Answers0