194k views
5 votes
How can JDBC be used more efficiently in the Spring framework?

a) By using XML configuration for database connections.
b) By avoiding the use of connection pooling.
c) By using Spring's DataSource and JdbcTemplate for database operations.
d) By using Hibernate instead of JDBC.

1 Answer

3 votes

Final answer:

JDBC can be used more efficiently in the Spring framework by using Spring's DataSource and JdbcTemplate for database operations and XML configuration for database connections.

Step-by-step explanation:

In the Spring framework, JDBC can be used more efficiently by using Spring's DataSource and JdbcTemplate for database operations. The DataSource class in Spring provides a standardized and efficient way to manage database connections. It supports connection pooling, which helps in reusing established connections and improves performance by reducing the overhead of creating new connections.

Additionally, the JdbcTemplate class provides a higher-level abstraction for executing database operations, handling exceptions, and managing resources. It simplifies the code by removing the need for boilerplate JDBC code.

Using XML configuration for database connections is also a good practice, as it allows for easy management and configuration of database properties without modifying the code.

User Schenz
by
8.3k points