Database access in struts 2

java, jdbc, persistence, struts2

Solution

In a Java EE Web Application, database connections should be managed and pooled inside an EJB, the war should know nothing about the datasource or the database connection details.

If you can choose which technology to include in your Web App, I strongly suggest to let Spring manage your database connections.

Example of Struts2 + Spring integration.

Note: Spring libraries have nothing to do with Spring MVC, that is a framework alternative to Struts2.

Edit

Things change and nowadays for persistence / ORM I suggest pure Java EE's JPA2 over Spring.

Problem

I am using JDBC drivers in java action class file to access database in struts 2. But as mentioned on this website there is another way to access database in struts using tag in `struts.xml` file. But that is not working for me in struts 2. My question is is there any other more efficient way to access database in struts2 other than using JDBC drivers because I have to make connection each time I access any action class file? And I am not using hibernate only want to use Struts.

Original source