users@glassfish.java.net

Null Pointer Exception using Connetion class

From: <glassfish_at_javadesktop.org>
Date: Mon, 05 Nov 2007 08:18:10 PST

Hi,

[code]public class BuildCms {
    DataSource db;
    static Connection conn;
    // initialize DB connection in constructor
    public BuildCms() throws NamingException, SQLException {
        db= BuildCms.getJdbcPwacms();
        conn = db.getConnection();
    }

    public static DataSource getJdbcPwacms() throws NamingException {
        Context c = new InitialContext();
        return (DataSource) c.lookup("XXXXXXXXXXXXX");
    }
    
    public static String getCMSPage(String page) throws NamingException, SQLException {
        
  #####ERROR#####
      Statement state = conn.createStatement();

[/code]
The above code compiles fine but glassfish returns a nullpointer exception when the code is called from a servlet. I have no idea why? Can anyone please help me here?

Thanks
[Message sent by forum member 'hughacland' (hughacland)]

http://forums.java.net/jive/thread.jspa?messageID=243881