Solved

Webapp with postgresql

Posted on 2001-07-30
6
678 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

895 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