You declared "DataSource ds" inside the constructor and that "ds" is being initialized and not the "private DataSource ds".

-- Dirk


Vernon Smith wrote:
After following the TC instruction configure the DBCP with the container, I create a class to make a cleaner interface.

public class DBCPWrapper {
        private DataSource ds;

        public DBCPWrapper() {
                try {
                        Context ctx = new InitialContext();
                        if (ctx == null)
                                throw new Exception("Boom - No Context");
                        DataSource ds =
                                (DataSource) ctx.lookup("java:comp/env/jdbc/postgres");
                        } catch (Exception e) {
                                e.printStackTrace();
                }
        }

        public Connection getConnection() throws SQLException {
                Connection conn  = ds.getConnection(); <-- ds is NULL
                return conn;
        }
}

I don't understand why the data source is null in the getConnection method. I fix this problem by moving the body of the construtor into the getConnection method. I am not sure that is a right approach thought. Is a better way to get the thing done?

Thanks for your inputs.



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to