Solved

Webapp with postgresql

Posted on 2001-07-30
6
680 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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.

816 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

10 Experts available now in Live!

Get 1:1 Help Now