Skip site navigation (1) Skip section navigation (2)

Re: problem to connect to database

From: Erwan Arzur <erwan(at)free(dot)fr>
To: Melanie Bergeron <mbergeron_pg(at)globeecom(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: problem to connect to database
Date: 2004-01-15 16:22:40
Message-ID: 4006BE50.2070100@free.fr (view raw or flat)
Thread:
Lists: pgsql-jdbc
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Melanie Bergeron wrote:
| Hi all!
|
| I really need your help for this.  I installed the JDBC driver on my
| machine by copying the jar file in C:\Program Files\Apache Software
| Foundation\Tomcat 5.0\common\lib\pg73jdbc3.jar and set environment
| variable CLASSPATH to this path.  I  create a JSP page (code below).
| The first time I launched this JSP page, all was ok.  I don't use it
| since last week but when I try to launched it yesterday, I got an error
| to connecting database :
|
| Error establishing the connection : Something unusual has occured to
| cause the driver to fail. Please report this exception: Exception: {0}
|
| So, I don't think the error come from my code because it already work
| with the same code but I don't know what I do to cause this error now.
| Any help will be greatly appreciated.
|
| Melanie
|
|
| -------code for jsp page---------
| <%
|  /* Load the JDBC Driver */
|  try {
|    Class.forName("org.postgresql.Driver");
|  }catch(ClassNotFoundException cnfe) {
|    out.println("<BR>Error loading driver " + cnfe + "<BR>");
|  }
|  /* Define the connection URL */
|  String dbName = "gec_test";
|  String host = "localhost";
|  String postgresqlUrl = "jdbc:postgresql://" + host + "/" + dbName;
|  /* Establish the connection */
|  String username = "bergeron.melanie";
|  String password = "*****";
|  try{
|    Connection connection = DriverManager.getConnection(postgresqlUrl,
| username, password);
|    ...
|    }
|    connection.close();
|  }catch(SQLException e){
|    out.println("<BR>Error establishing the connection : " + e + "<BR>");
|  }
|

Don't do that kind of ugly thing :-) !

You should setup tomcat so it manages a DBCP pool of connections for
you. Then you get a connection from the pool at your JSP page startup.

All is well documented, there's a specific DBCP/Postgresql sample in
this document :
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFABr5QtchshDF9KNYRAgtAAJ0aRczp62CPefdGQqhyK2bm+uo0wACfey43
AcJ9uL15zT9zXiAD5NLWEJ4=
=PeF1
-----END PGP SIGNATURE-----


In response to

pgsql-jdbc by date

Next:From: Melanie BergeronDate: 2004-01-15 16:33:31
Subject: problem starting postmaster as a service
Previous:From: Dave CramerDate: 2004-01-15 16:09:50
Subject: Re: problem to connect to database

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group