Re: DataSource lookup

From: luke(at)chipcity(dot)com(dot)au
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: DataSource lookup
Date: 2005-04-03 20:54:35
Message-ID: 20050403205435.GB1806@bench.chipcity.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,

03Apr2005 @ 11:33 Nico thusly spake
> How do I find out what's the name of the JNDI data source I need for a
> PostgreSQL connection pool?
> Currently I do this,
>
> javax.naming.Context env=(javax.naming.Context)
> new javax.naming.InitialContext().lookup("java:comp/env");
> pool=(DataSource)env.lookup("jdbc/"+dbname);
> connection=pool.getConnection("username","password");
>
> but then I get a MySQL connection(MySQL & PostgreSQL run both on server).
> I only have permission to my personal account, not the shared directories
> where I think the jndi resources are located. In my web.xml are no resources
> defined.

You can define the datasource in the context.xml file in the META-INF directory in your webapp.
You should have permissions for that because you should have permissions for the webapp
You can also define a datasource in the server.xml file, however that is in the 'server-root' conf file and it sounds like you don't have permission for that.

Here is an example from a context.xml file:

-this one is connecting to a cloudscape database, see 'driverClassName' (for postgres: 'org.postgresql.Driver')
-the url for a postgresql database would be 'jdbc:postgresql:dbname'
___________________________
/
<?xml version="1.0" encoding="UTF-8"?>
<Context path="">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="ROOT."
suffix=".log"
timestamp="true"/>
<Resource
driverClassName="COM.cloudscape.core.RmiJdbcDriver"
maxActive="4"
maxIdle="2"
maxWait="5000"
name="jdbc/dmit"
password=""
type="javax.sql.DataSource"
url="jdbc:cloudscape:rmi://localhost:1099/CloudscapeDB"
username=""/>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
\_____________________________

hth,
Luke
--
............._
.| .| |.|/.|_
.|__.|_|.|\.|_
.0421 276 282.

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Chris White (cjwhite) 2005-04-03 22:39:54 Re: JDBC and transactions
Previous Message Chris White (cjwhite) 2005-04-03 20:27:36 Re: JDBC and transactions