File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes JDBCRealm org.postgresql.Driver problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "JDBCRealm org.postgresql.Driver problem" Watch "JDBCRealm org.postgresql.Driver problem" New topic
Author

JDBCRealm org.postgresql.Driver problem

marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Hi

I am hoping someone may be able to help with my first web deployment on a production shared hosting environment that is set up for java/tomcat/postgresql.

In my servlet.xml under tomcat/config I have the following Realm element



unfortunately, I get the following error that indicates a problem with the accessing the postgresql driver.





Any ideas appreciated.

Thanks

Marten


when in doubt put it in parenthesis and stick a dollar sign in front of it, only good can come from this.
Sachin Pachari
Ranch Hand

Joined: Jan 16, 2012
Posts: 56

I think your connection url is wrong,

Please check the connection url, I think its missing the por number
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Thanks Sachin,

Unfortunately I do not think the port number is the issue. My hosting provider has the following example


which does not have a port number. Is there a standard port number for the databases in shared hosting environments?

Cheers

Marten
Sachin Pachari
Ranch Hand

Joined: Jan 16, 2012
Posts: 56

Try port number 5432, this is the default port number for postgresql
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

The driver will assume port 5432 by default. I cannot see anything wrong with that URL.

I was expecting to see a root cause in the stacktrace. Is there any information in the localhost logfile?

Customer surveys are for companies who didn't pay proper attention to begin with.
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Thanks Tim, thanks Sachin,

Ok, so I have added in the port 5432 number, still an issue

And I cannot see any other log files in the production environment, there is only the catalina.out

Any other areas to explore?

Cheers

Marten






Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

I can see from that log fragment that the JDBC driver is being loaded and registered (line 6 says so). So I would concentrate on this log entry:

SEVERE: Exception performing authentication


and look for configuration errors which might lead to that. By the way there wasn't any more log after what you posted, was there? I would sort of have expected another, lower-level, stack trace with lower-level detail.
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Thanks Paul,

I have relooked at the element in the servlet.xml, and changed the name of the roleNameCol column to role from type (changed on database too). is servlet.xml the only place where the JDBC Realm needs to be declared? Note the security Form works fine in my IDE environment so I don't image the HTML to be the problem.

Is there any other place to look for issues? for example, I still have the following element in my servlet.xml


Where else can I look?

Cheers

Marten





Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21


SEVERE: Exception performing authentication
java.sql.SQLException: org.postgresql.Driver


That would seem to indicate that the userid and password you're using are not valid for the particular way that you're logging in (which should be via the loopback device on 127.0.0.1). You might want to have the PostgreSQL security config file checked. Also, if I'm not mistaken, the PostgreSQL server needs to be restarted when that file (pg_hba, I believe) is changed or the new credentials/access won't be usable.
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Hi Tim, Paul, Sachin

I have resolved the problem.

1) I am in a shared hosting setup and do not have access to the pg_hba, after some discussion with my provider we found that ident authentication was set for the connection which was changed to explicitly use password authentication, not sure if this was the problem but I was able to access the database without the my password before this change.

2) Most likely the problem was with the driver. While I had a postgresql driver in the WEB_INF/lib for my app, I needed to add a driver to the tomcat/lib folder as well. I had a confounding problems with JDBCRealm and my app database working/not working.

Not sure exactly what it was in the end, a lot of mucking around on server.xml, web.xml as the and so forth so I learnt a lot in the process. Having resolved this issue, now working on my SSL.

Thanks for all your help.

Cheers

Marten
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

I can't say anything definitive, but you should not be placing database driver jars in your webapp (WEB-INF/lib). That would cause classpath problems assuming that you're using a server-managed database connection pool - which you should be.
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Thanks Tim

I took the driver out of the WEB-INF/lib folder and the app stopped working on account of no driver. When I added it in again it worked fine.

So where is the best place to put the driver? Tomcat needs a driver and so does the webapp, therefore I have it in two places at the moment... which doesn't seem right.

Cheers

Marten



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

You are probably getting your database connections by brute force, then.

You shouldn't do that. J2EE is far too expensive a platform to be developing low-performance applications in.

Put your driver jar back into WEB-INF/lib for the moment, but take the time to learn about the J2EE DataSource object and database connection pools.
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Thanks Tim,

I am getting the connections by brute force and trial and error, but I am also using a datasource

in the tomcat/conf/context.xml I have


then in tomcat/conf/servlet.xml (along with a driver in tomcat/lib) I have

as authentication works, it shows that the datasource is working.

then in my app I have


which only fails (when I don't have a driver in WEB-INF/lib) when I get to


so that seems odd.

Any advice on this would be great, but perhaps as I am using POJOs and not J2EE this error may be caused by a bigger gap in my knowledge than first appears to me.

Cheers

Marten
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Hmmmmm.

When I said "brute force", I meant having the usual class.forName lookup. You're using a Connection pool, all right, and I can't see anything obviously wrong. You say that you are throwing a JDBCException when you do the getConnection?
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178


The error is now a straight forward java.lang.ClassNotFoundException: org.postgresql.Driver as I am using the DataSourceRealm (so the problem has changed from the orignal topic)

There is probably something more nuanced in the set up which I will be able to resolve before going into production.

Thanks

Marten
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Then to confirm: you do have the Postgresql JDBC Driver jar (postgresql-jdbc2ee.jar or something similar) in the Tomcat/lib directory?
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

yes, I have postgresql-9.0-801.jdbc4.jar in the tomcat/lib. But my app will not work without the same jar in the WEB_INF/lib?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Check the contents of that jar. If your development system supports it. do this:


Just to make sure that it has at least one driver in it and that you have the driver classname properly spelled/capitalized.

Otherwise, I can only conclude you're doing something weird that I can't see without direct inspection of the WAR, because the classes in tomcat/lib jars are inherited by the webapps.
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Thanks Tim,

I got the following.

[xxx@squadron ~]$ jar tvf tomcat/lib/postgresql-9.0-801.jdbc4.jar | grep Driver
769 Mon Sep 20 21:38:50 EST 2010 org/postgresql/Driver$1.class
2623 Mon Sep 20 21:38:50 EST 2010 org/postgresql/Driver$ConnectThread.class
14725 Mon Sep 20 21:38:52 EST 2010 org/postgresql/Driver.class
1093 Mon Sep 20 21:38:54 EST 2010 org/postgresql/util/PSQLDriverVersion.class
22 Thu Jul 19 03:23:36 EST 2007 META-INF/services/java.sql.Driver


I am probably doing something wierd, as this is my first set up and there has been a lot of trial and error in getting it to work.

Cheers

Marten
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Yup. That looks good. Evidently your app has something wrong with it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBCRealm org.postgresql.Driver problem