Solved

Webapp with postgresql

Posted on 2001-07-30
6
677 Views
Last Modified: 2008-03-04
Hi,
   I have set up my postgresql in a linux RH7.0 machine. And my Tomcat webapp is on a NT mechine.
   I have test the postmaster..it runs well. And same to the tomcat.
   My question is how can I establish the JDBC connection from Tomcat jsp page in Nt to the postgresql in Linux mechine?
   What do i need to do?
   1) where should I install the jdbc driver? Nt or Linux?
   2) how to set the port for the database?

Thanks.
0
Comment
Question by:mkngau
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:sdussinger
ID: 6336551
1) The JDBC driver needs to be whereever the JSP page is. Since you have Tomcat running under NT, then NT is where the JDBC drivers should be installed.  They need to be installed somewhere so that your webapp can find them. You could put them into $TOMCAT_HOME/webapps/<yourwebapp>/WEB-INF/lib. That way when Tomcat starts, it'll add the jdbc jar file to the classpath for the webapp.

2) The default port for postgres is 5432. Assuming you haven't changed the default, this is the port to use. To connect from your JSP page:

     .
     .
     .

        String db = new String("jdbc:postgresql://localhost:8080/my_test");
        String usr = new String("username");
        String pwd = new String("password");

        Class.forName("org.postgresql.Driver");
                                     // Load database interface

        Connection conn =
            DriverManager.getConnection( db, usr, pwd );
     .
     .
     .

HTH.

--Steve
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6336553
Oops. Botched the previous code. The 8080 should read 5432, of course...

--Steve
0
 

Author Comment

by:mkngau
ID: 6336636
hi steve,
   thanks for the help. But, do I need to make changes in the pg_hba.conf ?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:mkngau
ID: 6336669
hi,
  I'm using postgres 7.1.2 so which jdbc driver is suitable for me? where can I get it?
   The error message is
ClassNotFoundException: Unable to load class postgresql.Driver SQLException: No suitable driver
0
 
LVL 4

Accepted Solution

by:
sdussinger earned 100 total points
ID: 6340097
1) The pg_hba.conf that is provided when postgres is first installed has a security policy which allows access by localhost and Unix sockets (not IP sockets.)

You'll probably have to add the address of your NT box to the pg_hba.conf file. The entry would look something like:

host   all   192.168.1.1   255.255.255.255   trust

That would allow full access from the IP 192.168.1.1

2) The JDBC driver is in /usr/lib/pgsql/jdbc7.0-1.2.jar. You'll need to ensure that your servlet has this in its classpath in order to find the driver.

--Steve
0
 

Author Comment

by:mkngau
ID: 6342995
Thanks steve,
    Thank you for your help. I have solved my problem.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now