[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Webapp with postgresql

Posted on 2001-07-30
6
Medium Priority
?
693 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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 400 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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

650 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