MySQL JDBC Datasource lookup fails after updating to mysql-connector-java-5.1.44

120 Views Asked by At

Consider following code snippet:

try
{//try to connect
    conn = DatasourceProvider.getDatasource("java:comp/env/jdbc/mysql/my_db").getConnection();
}
catch(Exception ex)
{//failed to acquire connection from the pool, retry
    ex.printStackTrace();
}

When I run it with mysql-connector-java-5.1.10-bin.jar loaded in tomcat 8.5 it works gracefully, but when I update to mysql-connector-java-5.1.44-bin.jar it throws following exception:

javax.naming.NameNotFoundException: Name [jdbc/mysql/my_db] is not bound in this Context. Unable to find [jdbc].
    at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)

This happens on both MySQL5.6 and MySQL5.7.
Any Idea?

0

There are 0 best solutions below