Обсуждение: jdbc problem with multiple connections

Поиск
Список
Период
Сортировка

jdbc problem with multiple connections

От
Chris Thompson
Дата:
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.

Re: jdbc problem with multiple connections

От
Aaron Mulder
Дата:
    Once a class is loaded, it doesn't have to be loaded again unless
you're in a different classloader.  This should be a clue to examine your
code *very* carefully.

On Sun, 6 Oct 2002, Chris Thompson wrote:
>     private String a_driver        = "org.postgresql.Driver";
>     private String b_driver        = "org.postgresql.Driver";
>     private String c_driver        = "org.postgresq.Driver";


Notice anything different?

Aaron


Re: jdbc problem with multiple connections

От
Chris Thompson
Дата:
What a prat i am, been starting at that for hours.

Thanks for the speedy replies, will look into buying glasses :)
Cheers

On Sun, 6 Oct 2002, Aaron Mulder wrote:

>     Once a class is loaded, it doesn't have to be loaded again unless
> you're in a different classloader.  This should be a clue to examine your
> code *very* carefully.
>
> On Sun, 6 Oct 2002, Chris Thompson wrote:
> >     private String a_driver        = "org.postgresql.Driver";
> >     private String b_driver        = "org.postgresql.Driver";
> >     private String c_driver        = "org.postgresq.Driver";
>
>
> Notice anything different?
>
> Aaron
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
> --
> Virus scanned by edNET.
>

--

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.