[opencms-dev] How to use the connection pool?
Thomas.Zirnsack at gfk.de
Thomas.Zirnsack at gfk.de
Wed Aug 1 11:48:00 CEST 2001
Hi,
I have written a class, that pulls out a connection from the OpenCMS
connection pool, retrieves some information from the database
and delivers it back to the caller. That works quite good inside
the OpenCMS system.
Now, someone wants to use this class outside of OpenCMS. Hence
ich have to create a connection pool on my own. Otherwise, I would
have to change the code in my class. Things look good until I
reach the point where I try to call DriverManger.getConnection('MyPool').
This call results in a NullPointerException.
Here is the code I use (for clarity I left out the try/catch blocks):
// code starts
CmsPool cp = new CmsPool
(
"jdbc:opencmspool:genericsql",
"com.sybase.jdbc2.jdbc.SybDriver",
"jdbc:sybase:Tds:x.x.x.x:y/opencms",
"user",
"password",
10,
20,
5,
120,
360
);
Class.forName("com.opencms.dbpool.CmsDriver");
con = DriverManager.getConnection("jdbc:opencmspool:genericsql");
// code ends
Here is what's spit out on the console:
// console output starts
D:\src\java\>java -classpath
./build;./opencms.jar;./jconn2.jar;./opencmsboot.jar Tester
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:0
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:1
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:2
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:3
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:4
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:5
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:6
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:7
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:8
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: creating new
connectio
n. Current Amount is:9
[com.opencms.dbpool.CmsPool] jdbc:opencmspool:genericsql: created
Exception in thread "main" java.lang.NullPointerException
at com.opencms.dbpool.CmsDriver.createPool(CmsDriver.java:202)
at com.opencms.dbpool.CmsDriver.getPool(CmsDriver.java:188)
at com.opencms.dbpool.CmsDriver.connect(CmsDriver.java:107)
at java.sql.DriverManager.getConnection(DriverManager.java:457)
at java.sql.DriverManager.getConnection(DriverManager.java:159)
at Tester.main(Tester.java:92)
// console output ends
Any pointers? What did I forget? For a day, I tried to understand the
OpenCMS code, but
I could not figure it out.
Thanks in advance for any help,
tom
More information about the opencms-dev
mailing list