Problems with Oracle 9i Thin Driver

Discussions

Web tier: servlets, JSP, Web frameworks: Problems with Oracle 9i Thin Driver

  1. Problems with Oracle 9i Thin Driver (3 messages)

    Hello,

    I am running Tomcat and Oracle 9i. I am trying to get my connection pooling working so I can use a JNDI. But I am having a problem.

    When I include everything in a jsp file it connects to the database and produces a result.

    Connection conn = null;
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver");

    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@xxx.xxx.xx.xx:1521:dev",
    "happy",
    "xxxx");

    When I have it in the Context I just get:
    A Java.nullpointerexception

    My server.xml is:
    <parameter>
          <name>url</name>
    <value>jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:dev</value>
              </parameter>
    With the same parameters for username and password as above.

    My servlet is:
    Context ctx = new InitialContext();
           if(ctx == null )
             throw new Exception("Oops - No Context");

           DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/database");

           if (ds != null)
             conn = ds.getConnection();

    All your help is appreciated:
    CC
  2. See the datasource howto in Tomcat's documentation:

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

    This explains everything quite well.
  3. Thanks,

    I did look at that but it only explains 8i, I didn't think it would be an issue to go to 9i but it is. Which is why I ask the question.

    What was listed on the Tomcat 5 Servlet/JSP Container - JNDI Datasource How-To did not help me with the problem.

    Any other ideas would be appreciated.

    CC
  4. Problems with Oracle 9i Thin Driver[ Go to top ]

    I put the driver in the TOMCAT_HOME/common/lib directory.


    Here's an excerpt out of my server.xml which shares an Oracle connection across multiple contexts (webapps). You'd probably need to change the username, password, and URL :)

     <Engine ... >
      <Host ... >

        <DefaultContext>
    <Resource name="dev" auth="Container"
    type="javax.sql.DataSource" />
    <ResourceParams name="dev">
    <parameter>
    <name>username</name>
    <value>scott</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>tiger</value>
    </parameter>
    <parameter>
           <name>maxActive</name>
    <value>10</value>
           </parameter>
           <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
           <parameter>
             <name>maxIdle</name>
    <value>2</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>oracle.jdbc.driver.OracleDriver</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:oracle:thin:@localhost:1521:dev</value>
    </parameter>
    </ResourceParams>
        </DefaultContext>
      
      <!-- Other Context related Stuff -->
      </Host>
    </Engine>