Fichas
Spring JDBC
Fichas del conjunto (10)
- 1Why do we need Spring JDBC when we already have Java JDBC?JDBC is the core API to connect your java application with any database vendor.
When we use Java JDBC there are multiple configuration steps, starting from loading the river to closing the DB connection developer has to manage.
When we use the Spring JDBC module under the Spring framework, it takes care of all low-level common JDBC operations and allows the developer to focus only on business logic. - 2What is DataSource in Java application?DataSource is a factory for connections to the physical data source.
In enterprise applications, the DataSource object is the preferred means of getting a connection to your database. - 3What are the three types of implementations of DataSource in Java applications?The DataSource interface is implemented by a driver vendor. There are three types of implementations:
Basic implementation - produces a standard Connection object
Connection pooling implementation -- produces a Connection object that will automatically participate in connection pooling.
Distributed transaction implementation -- produces a Connection object that may be used for distributed transactions and almost always participates in connection pooling. - 4What is Connection Pooling in an enterprise application?Connection pooling is a technique of creating and managing a pool of connections that are reused rather than created each time a connection is requested.
Connection pooling can greatly increase the performance of your Java application, while reducing overall resource usage.
Connection pool is a memory cache of database connections which is maintained by a connection pooling provider as a layer on top of any standard JDBC driver. - 5What default connection pool does spring boot use?Spring Boot uses HikariCP as the default connection pool.
HikariCP has great performance and concurrency. - 6What connection pool does spring boot supports?Spring Boot supports various popular connection pool providers as listed below:
HikariCP
Tomcat pooling Datasource
Commons DBCP2
Oracle UCP & OracleDataSource
Spring Framework’s SimpleDriverDataSource
H2 JdbcDataSource
PostgreSQL PGSimpleDataSource
C3P0 - 7What is the sequence of choosing various connection pools inside the Spring application?Spring Boot uses the following algorithm for choosing a specific implementation:
If HikariCP is available, Spring always chooses it.
Otherwise, if the Tomcat pooling DataSource is available, Spring will use it.
Otherwise, if Commons DBCP2 is available, Spring will use that.
If none of HikariCP, Tomcat, and DBCP2 are available and if Oracle UCP is available, Spring will use it. - 8What is Programmatic & Declarative Transaction Management in the Spring application?Spring provides both Programmatic and Declarative transaction management.
In Programmatic Transaction management we have transaction management code surrounding our business code.
It gives extreme flexibility but is difficult to maintain.
Whereas in Declarative Transaction management we separate the transaction management code from the business code.
We can configure Declarative Transaction management using both annotations and XML-based configuration.
Most Spring Framework users choose declarative transaction management as this option has the least impact on application code.
To summarize, Programmatic Transaction management is more flexible during development time but less flexible during application life. whereas Declarative Transaction management is less flexible during development time but more flexible during the application life - 9What does isolation and propagation attributes denote in @Transactional annotation e.g. @Transactional(isolation = xxx, propagation = xxx)?While using Declarative Transaction management we can provide isolation & propagation attributes which serve below purpose:
Isolation: The degree to which this transaction is isolated from the work of other transactions. For example, can this transaction see uncommitted writes from other transactions?
Propagation: Typically, all code within a transaction scope runs in that transaction. However, you can specify the behaviour if a transactional method is run when a transaction context already exists. For example, code can continue running in the existing transaction (the common case), or the existing transaction can be suspended, and a new transaction created. - 10What configurations do Spring JDBC & developer need to perform in the application?The table shows which actions Spring takes care of and which are developers’ responsibilities.
Steps Action Spring Developer
1 Define connection parameters. (developer)
2 Open the connection. (Spring)
3 Specify the SQL statement. (Developer)
4 Declare parameters and provide parameter values (developer)
5 Prepare and run the statement. (Spring)
6 Set up the loop to iterate through the results (if any). (Spring)
7 Do the work for each iteration. (developer)
8 Process any exception. (Spring)
9 Handle transactions. (spring)
10 Close the connection, the statement, and the result set. (Spring)
Información
- Descripción
- Spring JDBC Interview questions
- Creado por
- Jerry Reeves Jr
- Visitas
- 3
- Valoración