java - Tomcat - Oracle JNDI connection - how application can run without ojdbc jar in $CATALINA_HOMElib - Stack Overflow

I am setting up a legacy Web application and having a few questions. Currently the web application pack

I am setting up a legacy Web application and having a few questions. Currently the web application packed ojdbc jar under WEB-INF/lib and Tomcat context.xml has a resource tag referring to JNDI datasoure. It's Oracle database so the connection string is through oci (I am using Windows system)

<Resource name="jdbc/MainSource" 
      auth="Container" type="javax.sql.DataSource" 
      driverClassName="oracle.jdbc.driver.OracleDriver" 
      url="jdbc:oracle:oci:@username/password@tnsinstance" 
      validationQuery="SELECT sysdate from DUAL;"
      jdbcInterceptors="ConectionState" />

From what I can see, the Tomcat server don't have any ojdbc.jar under $CATALINA_HOME/lib directory. Then here are my questions

  1. How could the application run on JNDI if ojdbc is only available under WEB-INF/lib?
  2. Does OCI exempt the JNDI from providing the ojdbc jar (my understanding, it should not because Tomcat still look for implementation of driverClassName)?

Updated: A little further details to question2 - there is Oracle client installed on the server and within the installation there is ojdbc jar file, which should be in $PATH after ORACLE_HOME being registered. However I still don't think Tomcat server will reach out to OS $PATH to get ojdbc jar even if it is an Oracle OCI connection, according to Tomcat JNDI doc

I am setting up a legacy Web application and having a few questions. Currently the web application packed ojdbc jar under WEB-INF/lib and Tomcat context.xml has a resource tag referring to JNDI datasoure. It's Oracle database so the connection string is through oci (I am using Windows system)

<Resource name="jdbc/MainSource" 
      auth="Container" type="javax.sql.DataSource" 
      driverClassName="oracle.jdbc.driver.OracleDriver" 
      url="jdbc:oracle:oci:@username/password@tnsinstance" 
      validationQuery="SELECT sysdate from DUAL;"
      jdbcInterceptors="ConectionState" />

From what I can see, the Tomcat server don't have any ojdbc.jar under $CATALINA_HOME/lib directory. Then here are my questions

  1. How could the application run on JNDI if ojdbc is only available under WEB-INF/lib?
  2. Does OCI exempt the JNDI from providing the ojdbc jar (my understanding, it should not because Tomcat still look for implementation of driverClassName)?

Updated: A little further details to question2 - there is Oracle client installed on the server and within the installation there is ojdbc jar file, which should be in $PATH after ORACLE_HOME being registered. However I still don't think Tomcat server will reach out to OS $PATH to get ojdbc jar even if it is an Oracle OCI connection, according to Tomcat JNDI doc

Share Improve this question edited Nov 17, 2024 at 15:49 Dreamer asked Nov 17, 2024 at 14:25 DreamerDreamer 7,55127 gold badges110 silver badges198 bronze badges 1
  • You should provide more detailed information, how your application gets a connection to the database and clarify your problem. – Roman C Commented Nov 17, 2024 at 16:01
Add a comment  | 

2 Answers 2

Reset to default 0

Fallback to application-scoped resources occurs when an application avoids using the container-managed JNDI datasource and instead relies on resources bundled and loaded within the application itself. This can happen due to explicit configuration or as a backup mechanism when JNDI resources fail to initialise.

If the ojdbc.jar is missing from $CATALINA_HOME/lib, Tomcat cannot initialise the JNDI datasource, however, the application can still function if it directly loads the driver from WEB-INF/lib. Many legacy web applications were not designed to use container-managed JNDI datasources by default. They often have hardcoded connection logic as a fallback.

  1. You should put ojdbc jar in $CATALINA_HOME/lib.
  2. No

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745630764a4637095.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信