jdbc problem with multiple connections

Поиск
Список
Период
Сортировка
От Chris Thompson
Тема jdbc problem with multiple connections
Дата
Msg-id Pine.LNX.4.33L2.0210061308280.30623-100000@boyce.ednet.co.uk
обсуждение исходный текст
Ответы Re: jdbc problem with multiple connections  (Aaron Mulder <ammulder@alumni.princeton.edu>)
Список pgsql-jdbc
Hi,
I am opening 3 different database connection all calling the same method, which returns a
Connection or throws an Exception.

The first 2 attempts connections work fine, the third fails with a
ClassNotFoundException for org.postgresq.Driver. They are all using the
same org.postgresql.Driver.

Has anyone any suggestions as to why this might happen?

Postgres is running, accepting tcp connections on all hosts and
configured appropriately, no firewalls are in the way.

Cheers for any help,
Chris


// DBMgr.java
import java.sql.*;
/**
 * Example of problem code
 * Opens 3 connections, the first 2 work, third fails?!
 *
 */
public class DBMgr {

    private String a_driver        = "org.postgresql.Driver";
    private String a_url        = "jdbc:postgresql://server-a/a";
    private String a_user        = "a;
    private String a_password    = "a";

    private String b_driver        = "org.postgresql.Driver";
    private String b_url        = "jdbc:postgresql://server-b/b";
    private String b_user         = "b";
    private String b_password     = "b";

    private String c_driver        = "org.postgresq.Driver";
    private String c_url        = "jdbc:postgesql://server-c";
    private String c_user        = "c";
    private String c_password    = "c";

    public DBMgr() {}

    public Connection getAConn() throws ClassNotFoundException, SQLException {

        return connectDB(a_driver, a_url, a_user, a_password);
    }

    public Connection getBConn() throws ClassNotFoundException, SQLException {

        return connectDB(b_driver, b_url, b_user, b_password);
    }

    public Connection getCRMConn() throws ClassNotFoundException, SQLException {
        return connectDB(c_driver, c_url, c_user, c_password);
    }

    public void closeConn(Connection conn) {
        try {
            conn.close();
        } catch (SQLException e) {

            System.out.println(e.getMessage());
        }
    }

    /**
     * Returns a connection to a database
     * @param String db_driver
     * @param String db_url
     * @param String db_user
     * @param String db_password
     * @return Connection conn
     */
    public Connection connectDB(String db_driver, String db_url, String db_user, String db_password) throws
ClassNotFoundException,SQLException { 

        Connection connection;

        // try to load the postgres driver
        Class.forName(db_driver);

        // Connect to the database
        connection = DriverManager.getConnection(db_url, db_user, db_password);

        System.out.println("Got connection to " + db_driver + ", " + db_url + ", " + db_user + ", ******");

        return connection;
    }

}

--

This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender. Any
offers or quotation of service are subject to formal specification.
Errors and omissions excepted.  Please note that any views or opinions
presented in this email are solely those of the author and do not
necessarily represent those of edNET or lightershade ltd. Finally, the
recipient should check this email and any attachments for the presence of
viruses.  edNET and lightershade ltd accepts no liability for any damage
caused by any virus transmitted by this email.

--
--
Virus scanned by edNET.

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Thomas O'Dowd
Дата:
Сообщение: Re: JDBC and commit problems
Следующее
От: Aaron Mulder
Дата:
Сообщение: Re: jdbc problem with multiple connections