From: "Tommy Smith" <[EMAIL PROTECTED]> Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Using database pool Date: Mon, 08 Dec 2003 16:54:41 +0000
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Express yourself with cool emoticons - download MSN Messenger today! http://www.msn.co.uk/messenger
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
