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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]