You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ken Bowen <kb...@als.com> on 2008/04/17 15:53:38 UTC

Problem with datasource connecting to postgresql

Hi all,

I've successfully built a number of Tomcat projects using MySQL, but  
now I
have to also use PostgreSQL for a small demo app.  I'm having some  
trouble
with the context and datasource.

Setup: Tomcat 5.5.26 (unzipped from the Apache site)  on Mac OSX 10.5.2,
developing using Eclipse 6.0.1/MyEclipse;
PostreSQL 8.3.1 with postgresql-8.3-603.jdbc4.jar

The following test snippet works fine when run statically outside of  
Tomcat:

public static void main (String[] args)
                 throws ClassNotFoundException, SQLException
         {
                 Class pgClass = Class.forName("org.postgresql.Driver");
                 String url = "jdbc:postgresql://localhost:5432/ 
trackerdb";
                 Connection connection =  
DriverManager.getConnection(url, "trackermgr", "");
....goes on to retrieve rows from a table in trackerdb....

My Tomcat app has the following context.xml in META-INF:

<Context path="" debug="5" reloadable="true" crossContext="true">
    <Resource name="jdbc/trackerdb"  auth="Container"  
type="javax.sql.DataSource"
              maxActive="100" maxIdle="30" maxWait="10000"
              username="trackermgr" password=""
              driverClassName="org.postgresql.Driver"
              url="postgresql://localhost:5432/trackerdb"/>
</Context>

There is an AppListener which successully uses this to construct a  
DataSource.
However, when I get to attempting to obtain a Connection, I get the  
following Exception:

Exception: Cannot create JDBC driver of class 'org.postgresql.Driver'  
for connect URL 'postgresql://localhost:5432/trackerdb'
com.herenow.database.DAOException: Cannot create JDBC driver of class  
'org.postgresql.Driver' for connect URL 'postgresql://localhost:5432/ 
trackerdb'
         at  
com.herenow.database.DAOBaseData.getConnection(DAOBaseData.java:38)
   ....etc....

However, the jar file postgresql-8.3-603.jdbc4.jar is present in the  
app's lib:
tracker/WEB-INF/lib.  I've also tried moving the jar to tomcat's  
common/lib, but I get
the same Exception.

What am I missing here?
Thanks in advance,
Ken Bowen
~
~
~
~
~
~
~
~
~
"tomcat-user-postgresql-context" 43L, 1985C written


---------------------------------------------------------------------
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 with datasource connecting to postgresql

Posted by "Mark H. Wood" <mw...@IUPUI.Edu>.
You must be careful to distinguish the two different users involved.

The OS user would determine whether there is a permissions problem
with the JAR containing the PostgreSQL JDBC driver, but be
insignificant in actually connecting to the DBMS.  Ensuring that the
JAR is world-readable should eliminate this as a source of trouble.

The PostgreSQL user (I think it was "testmanager") partially
determines which entry in pg_hba is used to authorize the connection
-- the other determinant is the type of connection (local or network
socket, and (for network socket) the client host address).  The OS
user is not involved in this unless the DBMS is configured to pass
credentials through to e.g. PAM.

You might check the PostgreSQL monitor log for clues.  You may have to
adjust the logging configuration to be sure you get enough information
to be useful.  If you see no connection attempted, it wouldn't appear
to be a problem with the database user.

-- 
Mark H. Wood, Lead System Programmer   mwood@IUPUI.Edu
Typically when a software vendor says that a product is "intuitive" he
means the exact opposite.


Re: Problem with datasource connecting to postgresql

Posted by Ken Bowen <kb...@als.com>.
I used the same Java 1.5 (the only Java on the system); the snippet  
occurs in the the build
tree for the Tomcat project.  The snippet was run inside Eclipse which  
is running under
my own user login, so presumably that's how the snippet ran.  I'm not  
sure what the user is when
Tomcat runs -- I've started it both from Eclipse and from the shell  
script startup.sh.
The same Exception occurs.
[How do I determine the user in this case?]

Note that I've set the permissions for the entire tomcat installation  
to world -readable (r)
and world executable (x), so I would think the user wouldn't make a  
difference to Tomcat
being able to read the jar.


On Apr 17, 2008, at 10:00 AM, Jim Cox wrote:

> Do you use the same version of Java and run as the same user Tomcat  
> runs
> under when you run it "statically outside of Tomcat"?
>
> On Thu, Apr 17, 2008 at 9:53 AM, Ken Bowen <kb...@als.com> wrote:
>
>> Hi all,
>>
>> I've successfully built a number of Tomcat projects using MySQL,  
>> but now I
>> have to also use PostgreSQL for a small demo app.  I'm having some  
>> trouble
>> with the context and datasource.
>>
>> Setup: Tomcat 5.5.26 (unzipped from the Apache site)  on Mac OSX  
>> 10.5.2,
>> developing using Eclipse 6.0.1/MyEclipse;
>> PostreSQL 8.3.1 with postgresql-8.3-603.jdbc4.jar
>>
>> The following test snippet works fine when run statically outside of
>> Tomcat:
>>
>> public static void main (String[] args)
>>               throws ClassNotFoundException, SQLException
>>       {
>>               Class pgClass = Class.forName("org.postgresql.Driver");
>>               String url = "jdbc:postgresql://localhost:5432/ 
>> trackerdb";
>>               Connection connection =  
>> DriverManager.getConnection(url,
>> "trackermgr", "");
>> ....goes on to retrieve rows from a table in trackerdb....
>>
>> My Tomcat app has the following context.xml in META-INF:
>>
>> <Context path="" debug="5" reloadable="true" crossContext="true">
>>  <Resource name="jdbc/trackerdb"  auth="Container"
>> type="javax.sql.DataSource"
>>            maxActive="100" maxIdle="30" maxWait="10000"
>>            username="trackermgr" password=""
>>            driverClassName="org.postgresql.Driver"
>>            url="postgresql://localhost:5432/trackerdb"/>
>> </Context>
>>
>> There is an AppListener which successully uses this to construct a
>> DataSource.
>> However, when I get to attempting to obtain a Connection, I get the
>> following Exception:
>>
>> Exception: Cannot create JDBC driver of class  
>> 'org.postgresql.Driver' for
>> connect URL 'postgresql://localhost:5432/trackerdb'
>> com.herenow.database.DAOException: Cannot create JDBC driver of class
>> 'org.postgresql.Driver' for connect URL
>> 'postgresql://localhost:5432/trackerdb'
>>       at
>> com.herenow.database.DAOBaseData.getConnection(DAOBaseData.java:38)
>> ....etc....
>>
>> However, the jar file postgresql-8.3-603.jdbc4.jar is present in  
>> the app's
>> lib:
>> tracker/WEB-INF/lib.  I've also tried moving the jar to tomcat's
>> common/lib, but I get
>> the same Exception.
>>
>> What am I missing here?
>> Thanks in advance,
>> Ken Bowen
>> ~
>> ~
>> ~
>> ~
>> ~
>> ~
>> ~
>> ~
>> ~
>> "tomcat-user-postgresql-context" 43L, 1985C written
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>>


---------------------------------------------------------------------
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 with datasource connecting to postgresql

Posted by Jim Cox <sh...@gmail.com>.
Do you use the same version of Java and run as the same user Tomcat runs
under when you run it "statically outside of Tomcat"?

On Thu, Apr 17, 2008 at 9:53 AM, Ken Bowen <kb...@als.com> wrote:

> Hi all,
>
> I've successfully built a number of Tomcat projects using MySQL, but now I
> have to also use PostgreSQL for a small demo app.  I'm having some trouble
> with the context and datasource.
>
> Setup: Tomcat 5.5.26 (unzipped from the Apache site)  on Mac OSX 10.5.2,
> developing using Eclipse 6.0.1/MyEclipse;
> PostreSQL 8.3.1 with postgresql-8.3-603.jdbc4.jar
>
> The following test snippet works fine when run statically outside of
> Tomcat:
>
> public static void main (String[] args)
>                throws ClassNotFoundException, SQLException
>        {
>                Class pgClass = Class.forName("org.postgresql.Driver");
>                String url = "jdbc:postgresql://localhost:5432/trackerdb";
>                Connection connection = DriverManager.getConnection(url,
> "trackermgr", "");
> ....goes on to retrieve rows from a table in trackerdb....
>
> My Tomcat app has the following context.xml in META-INF:
>
> <Context path="" debug="5" reloadable="true" crossContext="true">
>   <Resource name="jdbc/trackerdb"  auth="Container"
> type="javax.sql.DataSource"
>             maxActive="100" maxIdle="30" maxWait="10000"
>             username="trackermgr" password=""
>             driverClassName="org.postgresql.Driver"
>             url="postgresql://localhost:5432/trackerdb"/>
> </Context>
>
> There is an AppListener which successully uses this to construct a
> DataSource.
> However, when I get to attempting to obtain a Connection, I get the
> following Exception:
>
> Exception: Cannot create JDBC driver of class 'org.postgresql.Driver' for
> connect URL 'postgresql://localhost:5432/trackerdb'
> com.herenow.database.DAOException: Cannot create JDBC driver of class
> 'org.postgresql.Driver' for connect URL
> 'postgresql://localhost:5432/trackerdb'
>        at
> com.herenow.database.DAOBaseData.getConnection(DAOBaseData.java:38)
>  ....etc....
>
> However, the jar file postgresql-8.3-603.jdbc4.jar is present in the app's
> lib:
> tracker/WEB-INF/lib.  I've also tried moving the jar to tomcat's
> common/lib, but I get
> the same Exception.
>
> What am I missing here?
> Thanks in advance,
> Ken Bowen
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> ~
> "tomcat-user-postgresql-context" 43L, 1985C written
>
>
> ---------------------------------------------------------------------
> 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
>
>