aspose file tools*
The moose likes JDBC and the fly likes First try with Glassfish and Postgresql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "First try with Glassfish and Postgresql" Watch "First try with Glassfish and Postgresql" New topic
Author

First try with Glassfish and Postgresql

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
Hi - I'm trying for the first time to use a database with JSF and Glassfish. However, before I try writing any code, I wanted to test out the code in chapter 10 of "Core JavaServer Faces" to see if database access works with my configuration, and it does not!

I configured the server as given in the book, and specified the JNDI name as "jdbc/mydb", and compiled the code provided, created a war file and deployed it. Online I found a file called "postgresql-8.3dev-601.jdbc4.jar.zip", copied it to my "/glassfish/domains/domain1/lib/ext/" folder, as instructed and started the server and the application. However, after starting the application and attempting to log in on its test page, I get the "Internal Error" message produced by the code. In checking the log at localhost:4848 I get various error messages saying that the connection was refused, including that I should check TCP/IP.

Could someone kindly advise me on what is going wrong, as until I can get an example running from the book, I can't go any further. The book says on page 466 that I first have to create a table with a few entries, with an example given, but nothing is said as to how I can do that.

Some help would be most appreciated.

Christopher Sharp
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

Christopher,
Can you access Postgresql through the command line? Do you have Glassfish configured to connect to Postgresql on the correct port.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
Originally posted by Jeanne Boyarsky:
Christopher,
Can you access Postgresql through the command line? Do you have Glassfish configured to connect to Postgresql on the correct port.


Hi Jeanne,

The whole problem is that I'm new to this and I don't know how to configure Glassfish to work with Postgresql, even though I followed the instructions in Geary and Hortmann.

I'm also unable to run Postgresql from the command line. I have Ubunto Linux, and installed postgresql version 8.3.0-1~feisty1 using the Synaptic Package Manager. I found that it installed a large number of files, including the executable posgres in the path /usr/lib/postgresql/8.3/bin . In attempting to execute this from root I get the message that it can only be started as an unprivileged user. When I attempt to execute it as a normal user it complains that I need to specify the --config-file or -D invocation or set the PGDATA environment varaible.

Also I don't know what connection port to use. For some reason Geary and Horstmann give 5432 in figure 10-2 on page 458, and I used exactly what they gave.

Christopher
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

Christopher,
I'm replying to the part about postgresql here. You might want to start a new thread in an app server forum (below on the forum list) for how to configure Glassfish. In general, I usual troubleshoot the database part first anyway. After all, you can't connect to a db through the server if the database isn't up!

When using postgresql, there are two parts.
1) Starting up postgresql - either as a service/startup script/cron job or through the provided "start postgresql" script. Does this work?
2) Next you access the database through a client. I think psql.exe comes bundled. (I'm not sure because I downloaded the bundle with a GUI client too.) The command for starting psql at the command line is:
PostgreSQL\8.2\bin> psql.exe" -h localhost -p <port> user password
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First try with Glassfish and Postgresql