struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nils-Helge Garli Hegvik" <nil...@gmail.com>
Subject Re: connection to db with pooling in Struts
Date Mon, 01 Dec 2008 07:17:05 GMT
That won't use the pool.

Take a look at some of the code snippets at [1]

Nils-H

[1] - http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

On Mon, Dec 1, 2008 at 8:09 AM, Adam Ruggles <a.ruggles@gmail.com> wrote:
>
> You can use this little snippet to get a connection:
>
>        public Connection getConnection(String url, String driverClassName, String
> username, String password) throws SQLException {
>                try {
>                        Class.forName(driverClassName);
>                } catch (ClassNotFoundException e) {
>                        throw new SQLException(e.getMessage());
>                }
>                if (username == null) {
>                        return DriverManager.getConnection(url);
>                }
>                return DriverManager.getConnection(url, username, password);
>        }
>
> Personally I use hibernate with spring or guice to deal with all that
> connection junk these days.
>
>
> gbattine wrote:
>>
>> Hello guys,
>> I'm newbie about Struts and I'm trying to understand a complex task (for
>> me), that is obtaining a connection from connection pool (I use dbcp for
>> this) and a datasource (that one of tomcat) and use this connection in dao
>> layer.
>> I'm trying to get this working, but it seems very difficult to me.
>> Could you help me?
>> I show what I did:
>> -I added context in server.xml of tomcat
>> -I added declaration into web.xml of application, like this:
>> <resource-ref>
>>       <description>DB Connection</description>
>>       <res-ref-name>jdbc/TestDB</res-ref-name>
>>       <res-type>javax.sql.DataSource</res-type>
>>       <res-auth>Container</res-auth>
>>   </resource-ref>
>>
>> Now my first question.
>> What's next step? Could you please post simple code and comment to
>> understand?
>> What I imagine is now to have something to retrieve a connection and pass
>> it to dao.
>> Could you help me?
>>
>> Thanks very much
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/connection-to-db-with-pooling-in-Struts-tp20738163p20767037.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message