cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tommy Smith" <jeff0...@hotmail.com>
Subject Using database pool
Date Mon, 08 Dec 2003 16:54:41 GMT
I am trying to access a database pool in other Java code (a 
HttpSessionAttributeListener)

My problem, is that I cannot return my connection as defined in 
cocoon.xconf.

Here is a snippet of code (the significant bits) can anyone offer any 
advice.

I must warn you that I am a relative new comer to Java.

Anyway, I always get a java.lang.NullPointerException???????

I'm not sure if the compose method is ever called.

public class MySessionFilter  implements HttpSessionAttributeListener,  
ThreadSafe, Composable, Disposable
{

private Connection con;
  private ResultSet rs;


  protected ComponentSelector dbselector;
  protected ComponentManager manager;

  public void compose(ComponentManager manager) throws ComponentException
  {

    this.dbselector = (ComponentSelector) 
manager.lookup(DataSourceComponent.ROLE + "Selector");
  }

  public void dispose()
  {
    this.manager.release(dbselector);
  }




protected final DataSourceComponent getDataSource(String pool) throws
ComponentException
{
   return (DataSourceComponent) this.dbselector.select(pool);
}


  public void attributeAdded(HttpSessionBindingEvent be)
  {
    Object sessionUser = be.getSession().getAttribute("user");
    System.out.println("Attribute User " +sessionUser);
    Connection conn = null;
    try
    {
//      compose(manager);
        DataSourceComponent dataSource =  getDataSource("abc");
      conn = dataSource.getConnection();
      Statement stmt = conn.createStatement();
      String sql = "update calib_users set logged_in = 'Z' where username = 
'simon'";
      System.out.println("Updated");
      ResultSet rs = stmt.executeQuery(sql);
    }
             catch (SQLException sqle)
  {
    System.out.println("No connection");
    return;
  }

        catch (Exception e)
    {

      System.out.println("Problem!!");
      e.printStackTrace();
    }


  }

_________________________________________________________________
Find a cheaper internet access deal - choose one to suit you. 
http://www.msn.co.uk/internetaccess


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message