开发者

Struts- Best way to connect to Mysql in struts 2?

Unable to determine what is the best way to connect to mysql database in struts..

  1. We can always use DriverManger and Class.forName() to connect.
  2. DataSource interface - but this has problems I am getting compliation error for

    DataSource dataSource = (DataSource)context.getAttribute(Globals.DATA_SOURCE_KEY); or when Action.Data_SOURCE_KEY is used. when searched I found that these variables are depricated.

How can I use connection pooling in struts?What is best place to place url,username,pass for database?DO i still have to use datasource configuration in same way in struts-config? Then why was this facility depricated?

Too many queastions but I cannot find a definite 开发者_StackOverflow社区source to learn struts. Struts doc can be but then revisions and backword compatibility are the issues which a learner cannot get easily... Pls suggest a good source to learn struts2.


Struts is an MVC framework, not a database access framework. You should use some sort tool for your Data Access Layer. Spring makes it really easy to manage connections, transactions, and the sort, and integrates well with ORM tools like Hibernate or the JPA implementation.

Where Struts fits in in this is that it will manage the request, delegate to an action, which in turn will invoke a service that uses your data access layer. You could put your DAL in your actions, but I wouldn't -- I would put them in a service.


Struts is a framework having the MVC approach. It makes you to create application in an efficient way. Connection between database is somewhat risk compare to someother connection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜