You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ashvini K Saxena <as...@fastmail.fm> on 2006/06/22 20:10:42 UTC

Problem configuring JNDI DataSource for Oracle

I am trying to use a datasource to access an Oracle database (Tomcat
5.5.9 and Oracle 9i). I have configured a datasource in the context.xml
as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Context
    reloadable="true">
  <Resource
    name="jdbc/reportdb"
    type="javax.sql.DataSource"
    url="jdbc:oracle:thin:rep@localhost:1521:rep"
    driverClassName="oracle.jdbc.OracleDriver"
    password="rep123"
    maxActive="4"
    maxWait="5000"
    maxIdle="2"
    username="rep"/>
  <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

In web.xml I am referring to the datasource as:

<resource-ref>
	<description>The Reports DataSource</description>
	<res-ref-name>jdbc/reportdb</res-ref-name>
	<res-type> javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>

The code for creating connections is something like this:
try {
	Context ctx = (Context)(new InitialContext().lookup("java:comp/env"));
	DataSource ds = (DataSource)ctx.lookup("jdbc/reportdb");
	Connection con = ds.getConnection();
} catch (NamingException e) {
	e.printStackTrace();
} catch (SQLException e) {
	e.printStackTrace();
}

The Oracle JDBC driver, classes12.jar is in common/lib.

At runtime I get the following error:
java.lang.NullPointerException
	org.apache.tomcat.dbcp.dbcp.DelegatingConnection.close(DelegatingConnection.java:151)
	org.apache.tomcat.dbcp.dbcp.PoolableConnection.reallyClose(PoolableConnection.java:95)
	org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.destroyObject(PoolableConnectionFactory.java:301)
	org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:883)
	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
	org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
	gaim.ui.report.action.ShowReport.doPost(ShowReport.java:42)

Has anyone encountered a similar problem and know of a solution? Is
there anything I am missing in my configuration?

Thanks and Regards,

Ashvini K Saxena
-- 
  Ashvini K Saxena
  ashvini@fastmail.fm

-- 
http://www.fastmail.fm - IMAP accessible web-mail


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem configuring JNDI DataSource for Oracle

Posted by Sourabh Antani <so...@yahoo.com>.
Ashvini,

I have faced a similar problem. Instance of the JNDI resource is not being created. In my case, the solution was to remove any spaces tomcat's path. I moved Tomcat directory from c:\Program Files\Apache Software Foundation\Tomcat to c:\Tomcat. JDK has a bug that it cannot find JNDI resource when there is a space in the path. See if that works for you.

Regards,

Sourabh

----- Original Message ----
From: Ashvini K Saxena <as...@fastmail.fm>
To: Tomcat Users List <us...@tomcat.apache.org>
Sent: Thursday, June 22, 2006 2:21:19 PM
Subject: Re: Problem configuring JNDI DataSource for Oracle

Nope, with that it only gives a proper error message,
Invalid connection string format, a valid format is: "host:port:sid"


On Fri, 23 Jun 2006 00:48:54 +0530, "Ashvini K Saxena"
<as...@fastmail.fm> said:
> I figured it out. I had followed Tomcat documentation while doing this.
> The Oracle example in the documentation mentioned url as
> jdbc:oracle:thin:myschema@127.0.0.1:1521:mysid
> Following that I specified my url as 
> jdbc:oracle:thin:rep@localhost:1521:rep while actually it should be
> jdbc:oracle:thin:rep@localhost:1521/rep
> 
> With that change, it worked!
> 
> Ashvini 
> 
> On Thu, 22 Jun 2006 23:40:42 +0530, "Ashvini K Saxena"
> <as...@fastmail.fm> said:
> > I am trying to use a datasource to access an Oracle database (Tomcat
> > 5.5.9 and Oracle 9i). I have configured a datasource in the context.xml
> > as follows:
> > 
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Context
> >     reloadable="true">
> >   <Resource
> >     name="jdbc/reportdb"
> >     type="javax.sql.DataSource"
> >     url="jdbc:oracle:thin:rep@localhost:1521:rep"
> >     driverClassName="oracle.jdbc.OracleDriver"
> >     password="rep123"
> >     maxActive="4"
> >     maxWait="5000"
> >     maxIdle="2"
> >     username="rep"/>
> >   <WatchedResource>WEB-INF/web.xml</WatchedResource>
> > </Context>
> > 
> > In web.xml I am referring to the datasource as:
> > 
> > <resource-ref>
> >     <description>The Reports DataSource</description>
> >     <res-ref-name>jdbc/reportdb</res-ref-name>
> >     <res-type> javax.sql.DataSource</res-type>
> >     <res-auth>Container</res-auth>
> >     <res-sharing-scope>Unshareable</res-sharing-scope>
> > </resource-ref>
> > 
> > The code for creating connections is something like this:
> > try {
> >     Context ctx = (Context)(new InitialContext().lookup("java:comp/env"));
> >     DataSource ds = (DataSource)ctx.lookup("jdbc/reportdb");
> >     Connection con = ds.getConnection();
> > } catch (NamingException e) {
> >     e.printStackTrace();
> > } catch (SQLException e) {
> >     e.printStackTrace();
> > }
> > 
> > The Oracle JDBC driver, classes12.jar is in common/lib.
> > 
> > At runtime I get the following error:
> > java.lang.NullPointerException
> >     org.apache.tomcat.dbcp.dbcp.DelegatingConnection.close(DelegatingConnection.java:151)
> >     org.apache.tomcat.dbcp.dbcp.PoolableConnection.reallyClose(PoolableConnection.java:95)
> >     org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.destroyObject(PoolableConnectionFactory.java:301)
> >     org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:883)
> >     org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
> >     org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
> >     gaim.ui.report.action.ShowReport.doPost(ShowReport.java:42)
> > 
> > Has anyone encountered a similar problem and know of a solution? Is
> > there anything I am missing in my configuration?
> > 
> > Thanks and Regards,
> > 
> > Ashvini K Saxena
> > -- 
> >   Ashvini K Saxena
> >   ashvini@fastmail.fm
> > 
> > -- 
> > http://www.fastmail.fm - IMAP accessible web-mail
> > 
> > 
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> > 
> -- 
>   Ashvini K Saxena
>   ashvini@fastmail.fm
> 
> -- 
> http://www.fastmail.fm - The professional email service
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
-- 
  Ashvini K Saxena
  ashvini@fastmail.fm

-- 
http://www.fastmail.fm - The professional email service


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org






Re: Problem configuring JNDI DataSource for Oracle

Posted by Ashvini K Saxena <as...@fastmail.fm>.
Nope, with that it only gives a proper error message,
Invalid connection string format, a valid format is: "host:port:sid"


On Fri, 23 Jun 2006 00:48:54 +0530, "Ashvini K Saxena"
<as...@fastmail.fm> said:
> I figured it out. I had followed Tomcat documentation while doing this.
> The Oracle example in the documentation mentioned url as
> jdbc:oracle:thin:myschema@127.0.0.1:1521:mysid
> Following that I specified my url as 
> jdbc:oracle:thin:rep@localhost:1521:rep while actually it should be
> jdbc:oracle:thin:rep@localhost:1521/rep
> 
> With that change, it worked!
> 
> Ashvini 
> 
> On Thu, 22 Jun 2006 23:40:42 +0530, "Ashvini K Saxena"
> <as...@fastmail.fm> said:
> > I am trying to use a datasource to access an Oracle database (Tomcat
> > 5.5.9 and Oracle 9i). I have configured a datasource in the context.xml
> > as follows:
> > 
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Context
> >     reloadable="true">
> >   <Resource
> >     name="jdbc/reportdb"
> >     type="javax.sql.DataSource"
> >     url="jdbc:oracle:thin:rep@localhost:1521:rep"
> >     driverClassName="oracle.jdbc.OracleDriver"
> >     password="rep123"
> >     maxActive="4"
> >     maxWait="5000"
> >     maxIdle="2"
> >     username="rep"/>
> >   <WatchedResource>WEB-INF/web.xml</WatchedResource>
> > </Context>
> > 
> > In web.xml I am referring to the datasource as:
> > 
> > <resource-ref>
> > 	<description>The Reports DataSource</description>
> > 	<res-ref-name>jdbc/reportdb</res-ref-name>
> > 	<res-type> javax.sql.DataSource</res-type>
> > 	<res-auth>Container</res-auth>
> > 	<res-sharing-scope>Unshareable</res-sharing-scope>
> > </resource-ref>
> > 
> > The code for creating connections is something like this:
> > try {
> > 	Context ctx = (Context)(new InitialContext().lookup("java:comp/env"));
> > 	DataSource ds = (DataSource)ctx.lookup("jdbc/reportdb");
> > 	Connection con = ds.getConnection();
> > } catch (NamingException e) {
> > 	e.printStackTrace();
> > } catch (SQLException e) {
> > 	e.printStackTrace();
> > }
> > 
> > The Oracle JDBC driver, classes12.jar is in common/lib.
> > 
> > At runtime I get the following error:
> > java.lang.NullPointerException
> > 	org.apache.tomcat.dbcp.dbcp.DelegatingConnection.close(DelegatingConnection.java:151)
> > 	org.apache.tomcat.dbcp.dbcp.PoolableConnection.reallyClose(PoolableConnection.java:95)
> > 	org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.destroyObject(PoolableConnectionFactory.java:301)
> > 	org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:883)
> > 	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
> > 	org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
> > 	gaim.ui.report.action.ShowReport.doPost(ShowReport.java:42)
> > 
> > Has anyone encountered a similar problem and know of a solution? Is
> > there anything I am missing in my configuration?
> > 
> > Thanks and Regards,
> > 
> > Ashvini K Saxena
> > -- 
> >   Ashvini K Saxena
> >   ashvini@fastmail.fm
> > 
> > -- 
> > http://www.fastmail.fm - IMAP accessible web-mail
> > 
> > 
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> > 
> -- 
>   Ashvini K Saxena
>   ashvini@fastmail.fm
> 
> -- 
> http://www.fastmail.fm - The professional email service
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
-- 
  Ashvini K Saxena
  ashvini@fastmail.fm

-- 
http://www.fastmail.fm - The professional email service


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem configuring JNDI DataSource for Oracle

Posted by Ashvini K Saxena <as...@fastmail.fm>.
I figured it out. I had followed Tomcat documentation while doing this.
The Oracle example in the documentation mentioned url as
jdbc:oracle:thin:myschema@127.0.0.1:1521:mysid
Following that I specified my url as 
jdbc:oracle:thin:rep@localhost:1521:rep while actually it should be
jdbc:oracle:thin:rep@localhost:1521/rep

With that change, it worked!

Ashvini 

On Thu, 22 Jun 2006 23:40:42 +0530, "Ashvini K Saxena"
<as...@fastmail.fm> said:
> I am trying to use a datasource to access an Oracle database (Tomcat
> 5.5.9 and Oracle 9i). I have configured a datasource in the context.xml
> as follows:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Context
>     reloadable="true">
>   <Resource
>     name="jdbc/reportdb"
>     type="javax.sql.DataSource"
>     url="jdbc:oracle:thin:rep@localhost:1521:rep"
>     driverClassName="oracle.jdbc.OracleDriver"
>     password="rep123"
>     maxActive="4"
>     maxWait="5000"
>     maxIdle="2"
>     username="rep"/>
>   <WatchedResource>WEB-INF/web.xml</WatchedResource>
> </Context>
> 
> In web.xml I am referring to the datasource as:
> 
> <resource-ref>
> 	<description>The Reports DataSource</description>
> 	<res-ref-name>jdbc/reportdb</res-ref-name>
> 	<res-type> javax.sql.DataSource</res-type>
> 	<res-auth>Container</res-auth>
> 	<res-sharing-scope>Unshareable</res-sharing-scope>
> </resource-ref>
> 
> The code for creating connections is something like this:
> try {
> 	Context ctx = (Context)(new InitialContext().lookup("java:comp/env"));
> 	DataSource ds = (DataSource)ctx.lookup("jdbc/reportdb");
> 	Connection con = ds.getConnection();
> } catch (NamingException e) {
> 	e.printStackTrace();
> } catch (SQLException e) {
> 	e.printStackTrace();
> }
> 
> The Oracle JDBC driver, classes12.jar is in common/lib.
> 
> At runtime I get the following error:
> java.lang.NullPointerException
> 	org.apache.tomcat.dbcp.dbcp.DelegatingConnection.close(DelegatingConnection.java:151)
> 	org.apache.tomcat.dbcp.dbcp.PoolableConnection.reallyClose(PoolableConnection.java:95)
> 	org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.destroyObject(PoolableConnectionFactory.java:301)
> 	org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:883)
> 	org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
> 	org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
> 	gaim.ui.report.action.ShowReport.doPost(ShowReport.java:42)
> 
> Has anyone encountered a similar problem and know of a solution? Is
> there anything I am missing in my configuration?
> 
> Thanks and Regards,
> 
> Ashvini K Saxena
> -- 
>   Ashvini K Saxena
>   ashvini@fastmail.fm
> 
> -- 
> http://www.fastmail.fm - IMAP accessible web-mail
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
-- 
  Ashvini K Saxena
  ashvini@fastmail.fm

-- 
http://www.fastmail.fm - The professional email service


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org