What is a common strategy for handling the situation when all connections in the pool are in use?
- Automatically create more connections
- Ignore the situation
- Terminate the application
- Wait for a connection to become available
Waiting for a connection to become available is a common strategy, ensuring that the application doesn't crash when all connections in the pool are in use.
What is the impact of setting a very high or very low size for the connection pool?
- Both high and low sizes have a negative impact on performance.
- High size can lead to resource wastage, while low size may cause performance issues.
- High size improves performance, but low size reduces resource usage.
- Setting size doesn't affect performance.
Setting a very high size for the connection pool can lead to resource wastage, while a very low size may cause performance issues. It's essential to find an optimal size to balance performance and resource usage effectively.
How can stale or broken database connections in the pool be handled effectively?
- By ignoring them and letting the database manage it.
- By logging the issue and continuing to use the connection.
- By notifying the database administrator.
- By removing them from the pool and establishing new connections.
Stale or broken database connections in the pool can be handled effectively by removing them from the pool and establishing new connections. This helps maintain a reliable and efficient connection pool for the servlet container.
In connection pooling, the pool size is defined by the _________ and _________ parameters.
- initialConnections, maxConnections
- initialSize, maxSize
- minConnections, maxConnections
- minSize, maxSize
In connection pooling, the pool size is defined by the initialSize and maxSize parameters.
A __________ strategy in connection pooling helps to optimize resource utilization under varying load conditions.
- Adaptive Allocation
- Dynamic Allocation
- Incremental Allocation
- Static Allocation
An Adaptive Allocation strategy in connection pooling helps optimize resource utilization under varying load conditions.
A web application experiences intermittent database connection issues. What connection pooling feature should be evaluated to resolve this?
- Connection Retry
- Idle Timeout
- Max Pool Size
- Min Pool Size
To address intermittent database connection issues, one should evaluate the Max Pool Size setting in connection pooling, which determines the maximum number of connections that can be created.
In a high-load scenario, a web application is unable to obtain database connections quickly. What aspect of connection pooling should be optimized?
- Acquire Increment
- Idle Timeout
- Max Idle Time
- Min Pool Size
To optimize obtaining database connections in a high-load scenario, focus on the Acquire Increment setting, which determines how many connections are added to the pool when all connections are in use.
How do you set a parameter in a PreparedStatement?
- Using the set() method.
- Using the setInt() method.
- Using the setParameter() method.
- Using the setParameter(int index, Object value) method.
Parameters in a PreparedStatement are set using specific methods like setInt(), setString(), etc., depending on the data type of the parameter.
What is a CallableStatement used for in JDBC?
- Executing DDL statements.
- Executing batch updates.
- Executing dynamic SQL queries.
- Executing stored procedures.
CallableStatement is used in JDBC for executing stored procedures in the database, providing a way to call database stored procedures from Java code.
How does PreparedStatement help in preventing SQL injection attacks?
- It automatically escapes special characters in the SQL query.
- It encrypts the entire SQL query.
- It relies on client-side validation.
- It uses parameterized queries.
PreparedStatement helps prevent SQL injection attacks by using parameterized queries, ensuring that user input is treated as data and not executable code.