Académique Documents
Professionnel Documents
Culture Documents
The above mentioned methods are what you typically see in DAOs,
create, read, update and delete.
Below is the project structure:
I have passed the sql statement that I want to be issued for the
database along with the values I wanted to save. You can use other
version of update as per your requirement.
What the template object do is that before it issue the SQL it will
automatically acquire a database connection, it will prepare the
statement and then it will execute the statement that I passed in
together with all of the values correctly bound into that SQL. Finally it
will clean up the resources it used. I might need to think about
exception handling but I will talk about it in another session.
NOTE: If some class is being used only in one class, then it is common
to declare the required class in the same file. I have created the one
called BookMapper. The rule in java that you can only have one public
class in the file but you have inner classes if required.
Below is the implementation:
Please refer spring doc to know the RowMapper working in detail.
I will be discussing in next session about wiring JDBCTemplate and
how to write a nice and clean DAO.