Return to site

๐Ÿƒ๐ŸŽ“ SPRING CERTIFICATION QUESTION: What is the Template design ๐Ÿ“๐Ÿ“ pattern and what is the JDBC template?

ยท spring,vcp,java

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.๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡