Return to site

🍃🎓 SPRING CERTIFICATION QUESTION: What is the Template design 📏📐 pattern and what is the JDBC template?

November 19, 2022

Answer:

𝐓𝐞ðĶðĐðĨ𝐚𝐭𝐞 design pattern, commonly known as 𝐭𝐞ðĶðĐðĨ𝐚𝐭𝐞 ðĶðžð­ðĄðĻ𝐝 defines series of steps 🊜 which are executed in a particular order.

This order cannot be changed ❌🔄ïļ, but some of the steps can be altered or are required to be implemented by a subclass.

ð―ð‘‘ð‘ð‘ð‘‡ð‘’ð‘šð‘ð‘™ð‘Žð‘Ąð‘’ is a class that implements template method design pattern and performs some boilerplate JDBC operations ðŸ§Ū.

Thus the user is only required to define SQL statements and result set custom mappings 🔗.

 

Operations that are performed by the Jdbc template:

- Open 📭 the connection

  1. Prepare, and execute ⚡ statements
  2. Iterate â–ķïļ through the result set
  3. Exception ðŸŠē processing
  4. Transaction handling
  5. Close ðŸ“ī connection, statement, the result set

 

Operations that should be performed by the Jdbc template client:

  1. Define connection 🔌 parameters
  2. Specify SQL statement and its parameters
  3. Specify mappings 🔗 for each result set iteration

Examples of mentioned terms:

𝑓𝑖𝑛𝑑ðĩð‘Ķðķð‘Ēð‘ ð‘Ąð‘œð‘šð‘’ð‘Ÿðžð‘‘ - demonstrates a basic example of a template method design pattern.👇👇👇