Your AOLServer example is the way to go.
I think the confusion is that you use dbPool like a Python module, not a
Webware specific thing.
In Python Modules are executed and loaded once, no matter how many times
they are imported. Due to this simple fact you can create a class or
varriable in a module and that class will exist once, regardless of how
many times its called.
So you should create dbPool in a seperate module.
1) create a module called configuration.py that contains:
from MiscUtils.DBPool import DBPool
from pyPgSQL import PgSQL
# set up the database connection pool
datapool = DBPool(PgSQL, 5, 'localhost::databasename:user:pass')
#The actual syntax of 'localhost::databasename:user:pass' will depend
upon your database connector
2) When you want to use a connection:
from configuration import datapool
conn = datapool.getConnection()
c = conn.cursor()
c.execute('select "CalledCity" from "UniqueCalledCities"')
rsCity = c.fetchall()
c.execute('select "CalledState" from "UniqueCalledStates"')
rsState = c.fetchall()
A better way would be to put all of the database work into another
module and call that from a servlet.
from configuration import datapool,clientpool
c.execute("Select numrows from numrows")
summary['numrows'] = r.numrows
and in your servlet:
self..writeln("Summary: %s" % dataStats)
You should be able to get dbPool working outside of webware.
Write a simple test module that pulls some data out using dbPool and get
that running furst. You may need to add the webware directory to your
Adam Shimali wrote:
>Just like to say first of all how much I love Webware.
>Well personal confessions out of the way, I'd like to
>ask if anyone can help me get how to use DBPool.
>I noticed an earlier post (
>), but I have to admit I didn't really get the
>Where should you instantiate a DBPool? Can you
>initialise one for the use of all servlets in your
>For example let's say I'm using WebKit, have a
>SitePage that all my Webware servlets inherit from and
>I have created a number of servlets based on the
>SitePage e.g. Login.py , Main.py, AddItem.py etc. that
>all need to interact with a given database. I gather
>that I could just get my SitePage base class (or even
>the derived servlets if not all of them need database
>access) to just open and hold a connection which
>persists as long as the servlet does. So in the
>example above my application would have an open
>connection for each of the above three servlets.
>Now what if instead of the base or derived servlets
>opening a database connection, I wanted to create a
>pool of connections and then any of the servlets could
>grab a connection from the pool, use it and release
>when done. Where would I create the pool, and how
>would each servlet communicate with it? Do you create
>one in the __init__.py file for the package context?
>I think I'm exposing some deep conceptual confusion
>about the use of a DBPool in Webware. However I think
>that in some sense (probably incorrectly) I'm
>expecting it work like pooled database connections in
>AOLServer. That is, the pool exists within the
>execution environment of the webserver and so any
>"script" executing in that environment can make a call
>to the webserver's API that returns a connection to
>the database, which can be released when done with.
>Can something similar be done in Webware using the
>Yahoo! Plus - For a better Internet experience
>This SF.Net email sponsored by: Free pre-built ASP.NET sites including
>Data Reports, E-commerce, Portals, and Forums are available now.
>Download today and enter to win an XBOX or Visual Studio .NET.
>Webware-discuss mailing list
"I don't know what's wrong with my television set. I was getting
C-Span and the Home Shopping Network on the same station.
I actually bought a congressman."
- Bruce Baum