Just becuase Struts has something, does not mean you use all of it, just the main part. For example "bean create" is not MVC, the point of action is to pre poplate the bean, also better done with c:out.
For example the way you are trying to is deprecated.


The create a data source pool and JNDI name in Tomcat like this:

<Context path="" docBase="/wheremywaris/"
        debug="0"
        reloadable="false" crossContext="true">


<Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true"/>



<Resource name="my_jndi_name" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="bppool">

<parameter><name>url</name>
<value>jdbc:postgresql://localhost:5432/bp?autoReconnect=true</value> </parameter>
<parameter> <name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter>
<parameter> <name>driverClassName</name> <value>org.postgresql.Driver</value> </parameter>
<parameter> <name>maxIdle</name> <value>3</value> </parameter>
<parameter> <name>username</name> <value>dbuser</value> </parameter>
<parameter> <name>maxWait</name> <value>5000</value> </parameter>
<parameter> <name>maxActive</name> <value>10</value> </parameter>
<parameter> <name>password</name> <value>changeme</value> </parameter>
<parameter> <name>removeAbandoned</name> <value>true</value> </parameter>
<parameter> <name>removeAbandonedTimeout</name> <value>20</value></parameter>
</ResourceParams>
</Context>


Or like this in resin:
<database>
    <jndi-name>jdbc/db-pool</jndi-name>
    <driver type="org.postgresql.jdbc3.Jdbc3ConnectionPool" >
                <user>bpuser</user>
                <password>changeme</password>
                <serverName>localhost</serverName>
                <databaseName>dpname</databaseName>
    </driver>
    <max-connections>3</max-connections>
</database>

Add this to you web.xml:
<resource-ref>
        <res-ref-name>dppool</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
</resource-ref>


Then select a DAO (Hibrenate or iBatis)
For ibatis create a name such as this ibatis data source (based on JDNI data source:


<datasource name = "ids"

factory-class="com.ibatis.db.sqlmap.datasource.JndiDataSourceFactory"
            default = "true" >
   <property name="DBInitialContext" value= "java:comp/env" />
   <property name="DBLookup"         value= "dppool" />
</datasource>



Then in your code you can do something like this:
 _daoMap.setCurrentDataSourceName("ids");
List rows = _daoMap.executeQueryForList("dao_map_name", parmList);
This is real easy to unit test for CRUD.

You can then have a formbean map to "rows" list.
See how Struts makes you data agnoist, it's just a collection.
And you can deploy same war against production db or staging db, without re-compiling the war, thus what you test is what you use.
Of course, display tag takes list as an argument once place in request scope.
In actrion you pre populate the bean, and ... display tag gets it in scope.


<rant>
There are many web sites about doing this in detail, and many J2EE books Some cosnider J2EE a pre-requesite for Struts. (Another faq is servlet's api on user roles, Servlets api is used by Struts and others for seucirty. For some reasone people have home grow exotic security. If you do strange things... no one can help you, you are not on the main road.


Else somone else can tell you the deprecated way to do this for JDBC 1.0 users. That way is... as you noticed buggy and not suitable for large production sites. I wonder why JDBC users don't just use Servlets and Tomcat features, and use Struts. If you use Struts, you should use DAO, else do everything low level.
You know there are people that do Struts training and mentoring, some have used Struts since 2001. It's very cost effective, and some are looking for gigs.


I am done preaching for the day.. almost:
Do not use data source within Struts. Do use a DAO via JNDI!
<rant/>
.V



Ajay Kalidindi wrote:
Hi Vic,

 <data-sources>
   <data-source key="contact">
     <set-property property="autoCommit" value="true"/>
     <set-property property="description" value="Mysql Contacts"/>
     <set-property property="driverClass" value="com.mysql.jdbc.Driver"/>
     <set-property property="maxCount" value="5"/>
     <set-property property="minCount" value="2"/>
     <set-property property="password" value="password"/>
     <set-property property="url" value="jdbc:mysql://localhost:3306/db"/>
     <set-property property="user" value="user"/>
   </data-source>
 </data-sources>

above section in struts-config.xml is provided as part of struts to enable
DB connection pooling.

Also it works perfect for few hours.

I forgot to mention my database, it is mysql.

Regards

Ajay Kalidindi

-----Original Message-----
From: Vic Cekvenich [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 04, 2003 3:04 PM
To: [EMAIL PROTECTED]
Subject: OT:Re: connection pooling issue


This is not a Struts question IMO.


here is a FAQ for Wiki:

#1. No one should use connection pool, if you want for some (I can't think of a good one myself) do low level JDBC, you should use data source. You can look up the data source via JNDI. Things like (low level) RowSet take a data source as argument... don't worry about connections, you will mess them up, unless you a double nested finnaly block.

#2. If you use Struts... you should also use a DAO, such as iBatis.com.

So use a data source (not connections) via JNDI and... don't use data source, use a DAO.


.V


Ajay Kalidindi wrote:

Hi

The issue is:

1. I restart tomcat, everything works good with tomcat, struts, connection pool ...
  I monitered the catalina.out log and all looks good connecting/releasing etc.
2. After few hours I get the following error :

java.sql.SQLException: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream

I have already tried changing autocommit to true in struts-config.xml.

Any suggestions are welcome.

Env Info :

Redhat 9, Tomcat 4.1.29, struts 1.1, jdk 1.3 ...

Regards

Ajay Kalidindi




---------------------------------------------------------------------
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]



Reply via email to