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.
What method is used to execute a stored procedure using a CallableStatement?
- callProcedure()
- execute()
- executeProcedure()
- executeQuery()
The execute() method is used to execute a stored procedure using a CallableStatement.
How can you retrieve the output of a stored procedure using CallableStatement?
- getOutput()
- getOutputParameterValue()
- getProcedureOutput()
- getResultSet()
You can retrieve the output of a stored procedure using getOutputParameterValue() method in CallableStatement, which returns the value of a designated OUT parameter after the stored procedure execution.
In what scenarios is CallableStatement preferable over PreparedStatement?
- Executing SQL queries with input parameters
- Handling batch updates
- Handling stored procedure calls
- Optimizing read-only operations
CallableStatement is preferable when dealing with stored procedures as it allows the execution of precompiled SQL queries, making it suitable for scenarios where stored procedures are used.
A PreparedStatement can be optimized by the JDBC driver using __________.
- batch processing
- caching
- connection pooling
- query optimization
A PreparedStatement can be optimized by the JDBC driver using connection pooling, which involves reusing database connections to improve performance.
In a CallableStatement, the method _________ is used to execute a SQL function.
- execute()
- executeFunction()
- executeQuery()
- executeUpdate()
In a CallableStatement, the method executeFunction() is used to execute a SQL function.
To improve performance, a PreparedStatement uses _________ to precompile SQL statements.
- compile()
- precompile()
- prepare()
- prepareStatement()
To improve performance, a PreparedStatement uses the prepareStatement() method to precompile SQL statements.
Which method in a servlet is used by default to handle GET requests?
- doGet()
- doPost()
- init()
- service()
The doGet() method in a servlet is used by default to handle GET requests.
The CallableStatement method _________ is used to get the result set of a stored procedure.
- executeQuery()
- getCallResult()
- getProcedureResult()
- getResultSet()
The CallableStatement method getResultSet() is used to get the result set of a stored procedure.