I have just created a "pool" -- I hope it is really a pool. I used jtds
jdbc driver to MS SQL Server on Windows. You may find some thing similar.
Holp it helps.
1) bellow is the text in tomcat\conf\server.xml
<GlobalNamingResources>
<Resource name="jdbc/DirectSQL" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/DirectSQL">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>255</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>user1</value>
</parameter>
<parameter>
<name>password</name>
<value>passwd1</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>net.sourceforge.jtds.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:jtds:sqlserver://serverName:1433</value>
</parameter>
</ResourceParams>
...
2) bellow is the text in tomcat\conf\Catalina\localhost\ROOT.XML --I create
this file by myself
<Context path="" docBase="ROOT" debug="0" privileged="true">
<!-- Link to the user database using dbc:jtds:sqlserver -->
<ResourceLink name="jdbc/DirectSQL" global="jdbc/DirectSQL"
type="javax.sql.DataSource"/>
</Context>
This "name" is used in Java code. "global" is the name in xml file. they can
be different.
3) my test jsp file is in \tomcat\webapps\ROOT\zuo\
Context ctx = new InitialContext();
if (ctx == null) {
throw new Exception("Boom - No Context");
}
DataSource ds = (DataSource)
ctx.lookup("java:comp/env/jdbc/DirectSQL");
if (ds != null)
con = ds.getConnection();
if (con != null){
str = "select * from myTable";
pStateSearch = con.prepareStatement(str,
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY );
rs = pStateSearch.executeQuery();
....
That's all.
-----Original Message-----
From: Arora, Avinash [mailto:[EMAIL PROTECTED]
Sent: Monday, May 03, 2004 3:10 PM
To: Tomcat Users List
Subject: DB connection pool problem
Hi,
I am also having the problem with the connection pools. Since I am
writing an application first time by using connection pools, I created a
test application DBTest. I edited my server.xml and web.xml (of my
application in following way--
#added to server.xml
<Context path="/DBTest" docBase="DBTest" debug="0"
reloadable="true">
<ResourceParams name="jdbc/conversion">
<parameter>
<name>username</name>
<value>ROOT</value>
</parameter>
<parameter>
<name>password</name>
<value>PASSWORD</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/DB</value>
</parameter>
</ResourceParams>
</Context>
#web.xml
<web-app>
<description>MySQL Test App</description>
<resource-ref>
<res-ref-name>jdbc/conversion</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
And I added the following statements to my Java class, (which works
fine, when I use the connection objects by hardcoding the username and
db).--
Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
DataSource dataSource = (DataSource)ctx.lookup("jdbc/conversion");
But even after, making these changes, I cannot read any thing from
database. I was wondering what more changes I need to made. I also tried
to run my JAVA class (DAO) from command line, but I get the following
exception--
Need to specify class name in environment or system property, or as an
applet parameter, or in an application resource file:
java.naming.factory.initial
I tried to print outs the place where exception occurs in my code and
found that exception occurs at
dataSource = (DataSource)ctx.lookup("jdbc/conversion");
Can any body please comment on whats going on wrong? When I run from
command line, is tomcat used, I don't think so? So where is the problem?
Any ideas??
Avinash Arora
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]