• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JDBCRealm org.postgresql.Driver problem

 
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 56
Netbeans IDE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think your connection url is wrong,

Please check the connection url, I think its missing the por number
 
marten koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
Netbeans IDE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try port number 5432, this is the default port number for postgresql
 
Saloon Keeper
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
marten koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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






 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then to confirm: you do have the Postgresql JDBC Driver jar (postgresql-jdbc2ee.jar or something similar) in the Tomcat/lib directory?
 
marten koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 koomen
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28486
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup. That looks good. Evidently your app has something wrong with it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic