This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
hi, good day, everyone here ! i'm new in struts, can i know how to connect database using struts? say mySQL, i try to find it by googles, but still can't figure out the exact answer i want ....so kindly please guide me here ..thank you very much for your time !
hi, Gregg Bolinger , was impressed with your explanation, you have immediately bring me to the point, which i couldn't get information from books. thank you very much !!!
for my case, i using tomcat for development, as you mentioned using action, Data Access Object or POJO to connect database, do you mind to explain more on POJO ? and also data access object..is it a helper class ? which way is the best for connection, thank you very much for your time again ....and again
Originally posted by Alvin chew: for my case, i using tomcat for development, as you mentioned using action, Data Access Object or POJO to connect database, do you mind to explain more on POJO ? and also data access object..is it a helper class ? which way is the best for connection, thank you very much for your time again ....and again
POJO, or Plain Old Java Object, is just that. A plain java object that is agnostic to what type of application it is being used in. Basically, in your case, there would be nothing J2EE specific about any of the code. And you could take that class and use it in a desktop application or any other J2EE application.
A data access object isn't much different than a POJO except I use the term to mean an object that access a database for whatever reason. Something that should be done outside of your actions.
Both DAOs and POJOs can also be called "helper classes" if you wish. I have a lot of these in the current app I am working on.
The commons DBCP doesn't work properly, the connection reuse is never done, i was trying the application with DBCP with initial connections set at 25 and when i hit the page 26th time, the page never shows up, the error cannot retrieve connection from the pool. Although my application always closes the connection after using it. I have seen a lot of people complaining about this, don't know whether they have found the solutions for it or not.
I am now using the PoolMan which is based on JDBC 2.0 and which lacks some of the methods like returning the Generated keys for which i had to synchronize the objects to get the functionality. Except this, poolman is very efficient in reusing the connections.
If you are using the Commons DBCP haven't you got this problem anytime, if so how to solve?.
"Failure is not when you fall down; its only when you fail to get up again."
Originally posted by Shankar Narayana: If you are using the Commons DBCP haven't you got this problem anytime, if so how to solve?.
I have not ran across this problem yet. I know that Connector/J has some packages for Connection Pools but I have not used them and I don't know how well they work. But they should have the functionallity you are missing by using the other DataSource.
I am going to go ahead and move this thread to the Tomcat forum since it seems to be getting specific for that app server. [ August 15, 2004: Message edited by: Gregg Bolinger ]
Joined: Jan 08, 2004
hi, Gregg .. which datasource you recommend for mysql connection ? there have several like ibatis, hibernate ..and so on, is it necessary to have this rather than use raw jdbc ? thank you very much !
"iBatis, Hibernate and so on" are not DataSources.
iBatis is a data access framework. It depends on XML and SQL.
Hibernate is an ORM tool, bridging Objects to relational databases. It also relies on XML, but a proprietary query language (not SQL).
It is not *necessary* to use either of these API's (and there are dozens more), though many people would tell you to at least attempt to use some sort of database abstraction layer.
A DataSource is any object that implements javax.sql.DataSource, which is part of the JDBC API. So any JDBC driver provider should provide you with one. For example, com.mysql.jdbc.jdbc2.optional.MysqlDataSource for the connectorj driver package. (Don't go looking for it; if you've downloaded connectorj.jar, then you have it). You can then use the DataSource to obtain a connection. (I haven't mentioned anything about pooling yet).
Now we mention pooling: the whole point of DataSources (from my perspective) is to get one of two things: managed transactions and connection pooling.
Connection Pools, therefore (like poolman and DBCP) should also provide you with a javax.sql.DataSource. Look in the API for DBCP's org.apache.commons.dbcp.datasources package. Most classes (all?) will implement javax.sql.DataSource. But all you *really* care about is getting a connection right? So you configure the pool to use your jdbc driver's connection classes, and then use the pool's DataSource class to retrieve a connection.
As for the reported error with DBCP, I've never run across this error myself. I've used both Tomcat 4.1 and 5.0 series (which have 2 different versions of DBCP) and it's always worked.
Originally posted by Alvin chew: hi, Gregg .. which datasource you recommend for mysql connection ? there have several like ibatis, hibernate ..and so on, is it necessary to have this rather than use raw jdbc ? thank you very much !