Re: Unable to connect to DB using DataSource

2008-12-04 Thread André Warnier

Stefan Deitmer wrote:

André Warnier schrieb:

[...]
Ok, then another probably silly suggestion, but you might as well upturn 
this stone too.
Apart from the directories you named as already compared, have you 
compared the /usr/share/tomcat5.5 ?
That is where the Debian distributions usually install the base of the 
Tomcat 5.5 software (CATALINA_HOME).  /var/lib/tomcat5.5 is 
CATALINA_BASE (where this Tomcat instance actually runs).


As many lights on this list never tire to point out, packages for 
specific OS'es put things a bit all over the place, with soft links in 
even more places, which makes it difficult sometimes to figure out where 
things really are and what points to what.  The Debian Tomcat packager 
seems to have even more imagination than most.


You could of course remove the Debian package, and install a real 
Tomcat from the Tomcat site.  You would then probably get more help from 
this list (for reasons I do not discuss nor contradict).  The 
inconvenient is that you would lose the facilities of the Debian package 
manager for configuration, updating, resolving dependencies etc..




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Unable to connect to DB using DataSource

2008-12-04 Thread Stefan Deitmer
 [...]
 Ok, then another probably silly suggestion, but you might as 
 well upturn this stone too.
 Apart from the directories you named as already compared, 
 have you compared the /usr/share/tomcat5.5 ?
 That is where the Debian distributions usually install the 
 base of the Tomcat 5.5 software (CATALINA_HOME).  
 /var/lib/tomcat5.5 is CATALINA_BASE (where this Tomcat 
 instance actually runs).

I don't have access to the machine that has the problem right now,
but I looked at the other machine (the one that works), and I strongly
suspect you discovered my problem. There is a link in 
/usr/share/tomcat5.5/common/lib pointing to the postgres JDBC jar
in /usr/share/java, and I think I put that link there back then, but forgot
to write this down, so didn't do this on the second machine.
I will try this tonight and will report back, but I'm very confident
that this is the cause of the problem.

 
 As many lights on this list never tire to point out, packages 
 for specific OS'es put things a bit all over the place, with 
 soft links in even more places, which makes it difficult 
 sometimes to figure out where things really are and what 
 points to what.  The Debian Tomcat packager seems to have 
 even more imagination than most.
 
 You could of course remove the Debian package, and install a real 
 Tomcat from the Tomcat site.  You would then probably get 
 more help from this list (for reasons I do not discuss nor 
 contradict).  The inconvenient is that you would lose the 
 facilities of the Debian package manager for configuration, 
 updating, resolving dependencies etc..

I would much prefer to use the Debian package if possible, for
the reasons you cited. However, I'm aware that using a standard
installation has advantages, too.

Anyways, you just helped me understand my Tomcat installation
a little bit better, so thanks a lot!

Regards
Stefan
-- 
Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: 
http://www.gmx.net/de/go/multimessenger

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Unable to connect to DB using DataSource

2008-12-04 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Stefan,

I'm no expert with Axis WebService, but I do have a question about your
use of the javax.sql.DataSource object:

Stefan Deitmer wrote:
 This is how I access the DataSource in the Axis WebService's LifeCycle
 object startup routine:
 
public void startUp(ConfigurationContext configctx, AxisService
 service) {

...

service.addParameter(new Parameter(Constants.DATASOURCE, ds));

Is it customary to push a DataSource into the service's parameters?
Since the DataSource is always available via JNDI, why not simply grab
it from the JNDI context whenever you need it?

Going through JNDI has the added benefit of always getting you the right
object. If you were to reconfigure (or replace, really) the DataSource
in the JNDI context, your updates wouldn't be available to the web service.

SQLException while trying to get connection : Cannot load JDBC driver
 class 'org.postgresql.Driver'

I suspect you are just missing the PostgreSQL driver jar file. Can you
find it in any of the (hopefully) obvious places? I would start by
looking in /usr/share/tomcat5.5 and its subdirs.

 Replacing above code with the following works without errors:
 
try
{
Class.forName(org.postgresql.Driver);
conn =
 DriverManager.getConnection(jdbc:postgresql://localhost/database,
 user, password);
}catch (Exception e) {
LOG.error(SQLException while trying to get connection: 
+ e.getMessage());
}

Sounds like the driver JAR file is packaged with your webapp (that is,
in yourapp/WEB-INF/lib/postgresql.jar). If you want to use Tomcat's
connection pooling (and you probably /do/), then you need to MOVE that
JAR file from your webapp's lib directory into Tomcat's libraries
directory. For Tomcat 5.5, you should probably put it into common/lib
under your Tomcat's real installation directory (maybe
/usr/share/tomcat5.5/common/lib).

 This is my first project with Tomcat, Axis, JDBC and PostgreSQL, and
 also the first time I'm seriously using Java in a very long time,
 so please have some patience with me if I'm missing something essential
 here.


You provided a perfect amount of information, actually. Thanks for
providing all the info you did!

 How comes Class.forName works when I call
 it directly, but not when the DataSource class calls it internally?

When using the DataSource, you are attempting to use Tomcat's connection
pool. Tomcat needs to be able to load the driver from a JAR file
/before/ consulting your webapp's libraries. When you use the
DriverManager, you are bypassing all that and loading the driver
normally through your webapp's classloader.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkk4UwYACgkQ9CaO5/Lv0PArlQCgkDShHM1KPolqhie10rXy5T7l
ulsAn1HGPq3TL1ElwW6lWsafU4eFD409
=1tU5
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Unable to connect to DB using DataSource

2008-12-04 Thread Stefan Deitmer

André Warnier schrieb:

Stefan Deitmer wrote:

André Warnier schrieb:

[...]
Ok, then another probably silly suggestion, but you might as well 
upturn this stone too.
Apart from the directories you named as already compared, have you 
compared the /usr/share/tomcat5.5 ?
That is where the Debian distributions usually install the base of the 
Tomcat 5.5 software (CATALINA_HOME).  /var/lib/tomcat5.5 is 
CATALINA_BASE (where this Tomcat instance actually runs).


André, as I suspected earlier today, you were on the right track.
I put a link to postgresql.jar into /usr/share/tomcat5.5/common/lib, and 
it works now.

Thank you so much! Life is good again :)

Cheers
Stefan

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Unable to connect to DB using DataSource

2008-12-03 Thread Stefan Deitmer

Hello list.

I am trying to use a JDBC DataSource to connect to a PostgreSQL server 
from within an Axis WebService running in Tomcat.
What confuses me is that I managed to get this to work on one server, 
but now am failing miserably to do so on a second server.


The first server is a Debian Lenny with Tomcat 5.5 and Axis 1.4.1, 
running in a Xen DomU on a 64 bit AMD machine.
The second server is also running Lenny with the same Tomcat and Axis 
versions, but in a VirtualBox VM on a 32 bit Intel machine.


I have compared the whole directory tree of /var/lib/tomcat5.5, also 
/usr/share/java, /etc/default/tomcat5.5 and the startup scripts in 
/etc/init.d/tomcat5.5.
Everything is identical between the two servers, and still, #1 works, #2 
doesn't.


The error message tells me that it can't find the postgres JDBC driver. 
However, there is a symbolic link in /var/lib/tomcat5.5/share/lib
pointing to the driver in /usr/share/java. Also, I tried to open a 
connection directly, that is, using DriverManager.getConnection(),

it works, so it seems to be able to find the driver.

This is the configuration of the DataSource (in 
/var/lib/tomcat5.5/conf/server.xml):


Context path=/axis2 reloadable=true cachingAllowed=false
   Resource name=jdbc/pigaiadb auth=Container 
type=javax.sql.DataSource
 maxActive=100 maxIdle=10 maxWait=1000 
removeAbandoned=true  removeAbandonedTimeout=60
 username=user password=password 
driverClassName=org.postgresql.Driver

 validationQuery=select 1
 url=jdbc:postgresql://localhost/database /
/Context

This is how I access the DataSource in the Axis WebService's LifeCycle 
object startup routine:


   public void startUp(ConfigurationContext configctx, AxisService 
service) {

   Context initCtx = null;
   Context envCtx = null;
   DataSource ds = null;

   try {
   initCtx = new InitialContext();
   } catch (NamingException e) {
   LOG.error(InitContext Exception :  + e.getMessage());
   }

   try {
   envCtx = (Context) initCtx.lookup(java:comp/env);
   } catch (NamingException e) {
   LOG.error(envContext Exception :  + e.getMessage());
   }
  
   try {

   ds = (DataSource) envCtx.lookup(jdbc/pigaiadb);
   } catch (NamingException e) {
   LOG.error(DataSource Exception :  + e.getMessage());
   }
  
   try {

   service.addParameter(new Parameter(Constants.DATASOURCE, ds));
   } catch (AxisFault e) {
   LOG.error(Failed to add datasource parameter to context:  
+ e.getMessage());

   }
   }

And this is how I try to get the connection from the DataSource:

   try {
   conn = ((DataSource) 
serviceContext.getAxisService().getParameterValue(Constants.DATASOURCE)).getConnection();

   } catch (SQLException e) {
   LOG.error(SQLException while trying to get connection : 
   + e.getMessage());
   }

... which results in the following error message:

   SQLException while trying to get connection : Cannot load JDBC 
driver class 'org.postgresql.Driver'


and this stack trace:

java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at 
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1130)
at 
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)

...

Replacing above code with the following works without errors:

   try
   {
   Class.forName(org.postgresql.Driver);
   conn = 
DriverManager.getConnection(jdbc:postgresql://localhost/database, 
user, password);

   }catch (Exception e) {
   LOG.error(SQLException while trying to get connection: 
   + e.getMessage());
   }

This is my first project with Tomcat, Axis, JDBC and PostgreSQL, and 
also the first time I'm seriously using Java in a very long time,
so please have some patience with me if I'm missing something essential 
here. I would greatly appreciate some pointers as to how I
could nail down this problem. How comes Class.forName works when I call 
it directly, but not when the DataSource class calls it internally?


Thanks a lot in advance
Stefan

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Unable to connect to DB using DataSource

2008-12-03 Thread André Warnier

Stefan Deitmer wrote:

Hi.
You can totally disregard this, because I am really not competent.
But just because I saw this in your post :

at java.security.AccessController.doPrivileged(Native Method)

did you compare the line
TOMCAT_SECURITY=...
in /etc/default/tomcat5.5
between your systems ?
and maybe the files in /etc/tomcat5.5/policy.d ?




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Unable to connect to DB using DataSource

2008-12-03 Thread Stefan Deitmer

André Warnier schrieb:

Stefan Deitmer wrote:

Hi.
You can totally disregard this, because I am really not competent.
But just because I saw this in your post :

at java.security.AccessController.doPrivileged(Native Method)

did you compare the line
TOMCAT_SECURITY=...
in /etc/default/tomcat5.5
between your systems ?
and maybe the files in /etc/tomcat5.5/policy.d ?


TOMCAT_SECURITY is NO on both systems, and the contents of
/etc/tomcat5.5/policy.d are identical.
The line you cited from the stack trace made me think the same thing,
but as the security manager is off on both systems, I guess it can't be
the cause of my problems.

Thank you though!

Regards
Stefan

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Unable to connect to DB using DataSource

2008-12-03 Thread BEN HMIDA aymen
Hi,
There's something confusing in your post but i think you 've forgotten to 
specify the port number userd by postgres

-Message d'origine-
De : Stefan Deitmer [mailto:[EMAIL PROTECTED] 
Envoyé : jeudi 4 décembre 2008 08:35
À : Tomcat Users List
Objet : Re: Unable to connect to DB using DataSource

André Warnier schrieb:
 Stefan Deitmer wrote:

 Hi.
 You can totally disregard this, because I am really not competent.
 But just because I saw this in your post :

 at java.security.AccessController.doPrivileged(Native Method)

 did you compare the line
 TOMCAT_SECURITY=...
 in /etc/default/tomcat5.5
 between your systems ?
 and maybe the files in /etc/tomcat5.5/policy.d ?

TOMCAT_SECURITY is NO on both systems, and the contents of
/etc/tomcat5.5/policy.d are identical.
The line you cited from the stack trace made me think the same thing,
but as the security manager is off on both systems, I guess it can't be
the cause of my problems.

Thank you though!

Regards
Stefan

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]