Quote:
|
Originally Posted by dobell
So the way I have to use is:
- execute the query.
- read the results in the resultSet.
- close the connection.
Isn't it?
Or maybe I have to copy the resultSet to other object not related to the connecition?
Thanks
|
Yes. A typical design pattern for Java is to create ValueObjects and use a DAO to load them.
ie. say you have a table that represents a Person, you would likely have a PersonVO, with getXXX and setXXX methods for things like Lastname, firstname, etc.
Then you would have a PersonDAO with a method like selectPerson(id), selectPersonByLastname(), updatePerson(PersonVO), etc, which would perform the SQL, build the ValueObject, and return it.... or shred it into an INSERT/UPDATE.
If you want to learn more detail, look at the Java blueprints:
http://java.sun.com/blueprints/patterns/index.html