Re: Creating a data source

From: Larry Mulcahy <lmulcahy(at)qip(dot)qwest(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Creating a data source
Date: 2001-05-14 22:29:58
Message-ID: 3B005C66.B264AB4D@qip.qwest.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I have continued working on this and have learned some things I
didn't understand when I asked this question.

I have succeeded in deploying a PostgreSQL DataSource using the
file system service provider
(com.sun.jndi.fscontext.RefFSContextFactory,
http://java.sun.com/products/jndi/serviceproviders.html). I have
one small Java application that binds the DataSource to a name,
then another application can do a lookup on that name, do a
getConnection on the DataSource and with that access the database.

Now, I'd like to do connection pooling. After poring over the
archived messages of pgsql-jdbc and looking at the source code,
I'm having a hard time determining whether it's possible to do
this (without using some other software like PoolMan, Protomatter
or Tyrex). Some of the messages in the mailing list such as
http://fts.postgresql.org/db/mw/msg.html?mid=75748
suggest that the ConnectionPoolDataSource interface ought to be
implemented, but I can't find any classes in the "enterprise" jar
file or in the source tree that sound like this.

Is ConnectionPoolDataSource implemented?

Larry Mulcahy wrote:
>
> I'm trying to create a data source as described in paragraph
> 5.5.1 of the JDBC 2.0 Standard Extension API
> (http://java.sun.com/products/jdbc/jdbc20.stdext.pdf).
> (Another example: paragraph 3.7.2 "Deploying a Basic Datasource
> Object" in http://developer.java.sun.com/developer/Books/JDBCTutorial/).
>
> My application produces the output,
>
> java -classpath
> .:/usr/local/pgsql/share/java/postgresql.jar:/usr/local/java/jdbc2_0-stdext.jar
> Example
> Creating a new Context...
> Binding...
> Bind failed.
> Exception: javax.naming.NoInitialContextException: Need to specify class
> name in environment or system property, or as an applet parameter, or in
> an application resource file: java.naming.factory.initial
>
> I found various documentation about different ways to specify a value
> for java.naming.factory.initial. You can put it in
> $JAVA_HOME/lib/jndi.properties, you can specify it on the command line
> with -Djava.naming.factory.initial=..., you can create an environment
> Hashtable and pass it as one of the arguments to InitialContext as
> documented at http://java.sun.com/products/jndi/tutorial/beyond/env/.
> What I can't find is what value to actually give it for the
> InitialContextFactory. Am I supposed to write this myself?
>
> This seems like a routine common action that people must do all the
> time, but I can't seem to find good documentation about how to do it.
>
> Is there some administration that needs to be done behind the scenes,
> e.g. starting a JNDI server?
>
> Code follows:
>
> import javax.naming.InitialContext;
> import javax.naming.Context;
> import java.util.Hashtable;
>
> public class Example {
> public static void main(String args[])
> {
> org.postgresql.PostgresqlDataSource ds =
> new org.postgresql.PostgresqlDataSource();
> ds.setServerName("host");
> ds.setDatabaseName("database");
>
> Context ctx = null;
>
> System.out.println("Creating a new Context...");
> try {
> ctx = new InitialContext();
> }
> catch (Exception e) {
> System.out.println("Failed to create a new Context.");
> System.out.println("Exception: " + e);
> return;
> }
>
> System.out.println("Binding...");
> try {
> ctx.bind("jdbc/database", ds);
> }
> catch (Exception e) {
> System.out.println("Bind failed.");
> System.out.println("Exception: " + e);
> return;
> }
> }
> }

--
Larry Mulcahy lmulcahy(at)qip(dot)qwest(dot)net
PGP public key at:
http://pgpkeys.mit.edu:11371/pks/lookup?op=get&search=0x2C4C5A03

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Joseph Shraibman 2001-05-14 22:38:06 Re: Error Retrieving Date Records
Previous Message Jan Gacnik 2001-05-14 19:39:08 PostgreSQL on Mac OS X