Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set up a <Resource> in Tomcat 7 so that I don't need to use "java:/comp/env" in the code?
    primarykey
    data
    text
    <p>I am new to setting up JNDI resources and setting up JNDI resources in Tomcat.</p> <p>I inherited a servlet application. It runs on a test server via WebLogic. The servlet application accesses its database resource in the following way:</p> <pre><code>ctx = new InitialContext(); ds = (javax.sql.DataSource)ctx.lookup("myDataBaseName"); conn = ds.getConnection(); </code></pre> <p>When I tried that in a test JSP it doesn't work. I get</p> <pre><code>javax.naming.NameNotFoundException: Name myDataBaseName is not bound in this Context </code></pre> <p>However I was able to make the test JSP work if I altered the test JSP code thus:</p> <pre><code>ctx = new InitialContext(); Context envContext = (Context)ctx.lookup("java:/comp/env"); ds = (DataSource)envContext.lookup("myDataBaseName"); conn = ds.getConnection(); </code></pre> <p>I have this entry in TOMCAT_HOME/conf/context.html ( I'm just using it as a dev environment on my box )</p> <pre><code>&lt;Resource name="myDataBaseName" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@blahblahblah:1521:database3" username="joeuser" password="password" maxActive="20" maxIdle="30" maxWait="-1"/&gt; &lt;/Context&gt; </code></pre> <p>And I have this in my TOMCAT_HOME/conf/web.xml:</p> <pre><code>&lt;resource-ref&gt; &lt;res-ref-name&gt;myDataBaseName&lt;/res-ref-name&gt; &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; &lt;res-auth&gt;Container&lt;/res-auth&gt; &lt;/resource-ref&gt; </code></pre> <p>I read about 10 stackoverflow pages on related problems, but I am not familiar enough with setting up JNDI resources to abstract those solutions to my problem.</p> <p>How can I change the way I have Tomcat 7 set up to allow the existing servlet application to access its database as "myDatabaseName"? I don't have the option of altering the code in the servlet application or altering the way WebLogic is set up on the test server. </p> <p><strong>I need to alter the way my copy of Tomcat 7 is set up on my computer ( for a dev environment ) to allow the servlet application to access its database in the style of the first chunk of quoted code at the top of this post.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload