This example is for Struts 1.x, not Struts 2. Struts 2 provides no direct support for managing database connections, although one could achieve something like this rather readily using Spring, or probably with any other ObjectFactory.
Here's a tutorial which gets much more involved than your basic request, but which might help. Note that since the tutorial uses Hibernate, it isn't exactly what you asked for, but it also demonstrates using Spring to instantiate a Datasource, and then you could have Spring also instantiate your Action Classes and "inject" the datasource dependency into them. http://cwiki.apache.org/S2WIKI/struts-2-spring-2-jpa-ajax.html Let me issue the standard disclaimer that if you are doing a lot of database work in your Action classes, you may want to consider refactoring anyway. Joe On 1/16/07, Philippe Le Gal <[EMAIL PROTECTED]> wrote:
Hi, Thanks again. Is it possible that you give me the complete listing of this example because, I've problem to find how to initialize the 'context' object. Thanks Philippe Le mardi 16 janvier 2007 11:14, Stanislav a écrit: > in java action class you can also connect through struts db mechanisam: > DataSource dataSource = (DataSource) > context.getAttribute("org.apache.struts.action.DATA_SOURCE"); conn = > dataSource.getConnection(); > or direct to db > Connection conn = > DriverManager.getConnection (ConnectionURL,ConnectionUserName,ConnectionPass >word); > > > > From: Philippe Le Gal <[EMAIL PROTECTED]> > To: "Struts Users Mailing List" <user@struts.apache.org> > Subject: Re: [Struts 2] Database access > Date: Tue, 16 Jan 2007 11:08:28 +0100 > > ----- Original Message Follows ----- > > > Hi, > > > > Thanks for the information. > > I'm also looking for the mecanism of accessing the database in the java > > action class. > > > > Thanks > > > > Philippe > > > > Le mardi 16 janvier 2007 10:59, Stanislav a écrit : > > > in struts-config for sql database. > > > > > > <data-sources> > > > <data-source type="org.apache.commons.dbcp.BasicDataSource"> > > > <set-property property="driverClassName" > > > value="com.microsoft.jdbc.sqlserver.SQLServerDriver" /> > > > <set-property property="url" > > > value="jdbc:microsoft:sqlserver://xxx.xxx.xxx.xxx:1433;DatabaseName=xxx > > >xx;S electMethod=Cursor" /> <set-property property="username" > > > value="xxxxx" /> <set-property property="password" value="xxxxx" /> > > > <set-property property="maxActive" value="0" /> > > > <set-property property="maxWait" value="5000" /> > > > <set-property property="defaultAutoCommit" value="false" /> > > > <set-property property="defaultReadOnly" value="false" /> > > > </data-source> > > > </data-sources> > > > > > > > > > From: Philippe Le Gal <[EMAIL PROTECTED]> > > > To: user@struts.apache.org > > > Subject: [Struts 2] Database access > > > Date: Tue, 16 Jan 2007 10:53:12 +0100 > > > > > > ----- Original Message Follows ----- > > > > > > > Hi, > > > > > > > > I'm looking for a simple struts 2 database access example. > > > > > > > > Thanks for any url > > > > > > > > Philippe > > > > > > > > --------------------------------------------------------------------- > > > > 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] > > > > --------------------------------------------------------------------- > > 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Joe Germuska [EMAIL PROTECTED] * http://blog.germuska.com "The truth is that we learned from João forever to be out of tune." -- Caetano Veloso