SQL for Java Devs interview questions
Batching, Indexes, JDBC, JOINs, PreparedStatements, Repository Pattern
172 questions with answers and explanations · 171 flashcards
Questions (page 1 of 4)
- Why is it important to disable auto-commit mode for a JDBC transaction when performing multiple updates?Multiple choiceEasy
- How can JDBC transactions help maintain data integrity during an e-commerce checkout process?Multiple choiceMedium
- What would be the effect of not closing a PreparedStatement in a Java application?Multiple choiceMedium
- In JDBC, how do you ensure that SQL injection is prevented when executing a query that searches for a user by email?Multiple choiceMedium
- Why do teams use SQL JOINs to fetch relational data in a single query in production code?Multiple choiceMedium
- What should a repository method mainly encapsulate?Multiple choiceEasy
- How can you prevent the N+1 query problem when retrieving a list of orders with their customer details?Multiple choiceMedium
- How can using a PreparedStatement benefit a Java application that frequently executes the same query with different parameters?Multiple choiceMedium
- What does a RIGHT JOIN between two tables evaluate to?Multiple choiceMedium
- When using JDBC, why is it crucial to handle SQLExceptions properly?Multiple choiceHard
- Given a one-to-many relationship between 'products' and 'reviews', how can you retrieve all products with their reviews in a single SQL query while ensuring…Multiple choiceHard
- When using JDBC, which method ensures a SQL query is executed as a transaction?Multiple choiceMedium
- How does a PreparedStatement mitigate the risk of SQL injection?Multiple choiceMedium
- Why would you choose to use PreparedStatement over Statement in JDBC?Multiple choiceMedium
- Why is it important to handle SQLExceptions in JDBC properly?Multiple choiceMedium
- In JDBC, what is the primary advantage of using a PreparedStatement over a regular Statement?Multiple choiceMedium
- Which transaction isolation level in most JDBC databases is the default in Java?Multiple choiceEasy
- Why does the Repository Pattern in a Java application using JDBC for database operations matter in this design?Multiple choiceEasy
- What method should you use to move the cursor to the first row of a ResultSet object?Multiple choiceEasy
- What does an INNER JOIN between two tables on a foreign key evaluate to?Multiple choiceEasy
- In the context of JDBC, what is the best approach to handle exceptions to ensure reliable database interactions?Multiple choiceHard
- When extracting a 'price' column from a ResultSet, which method should be used to ensure the value is retrieved as a double?Multiple choiceMedium
- Why does encapsulating JDBC logic within a Repository when following a layered architecture help in practice?Multiple choiceMedium
- In a one-to-many relationship, how is the 'many' side typically represented in Java?Multiple choiceEasy
- In a JDBC batch process, how can you ensure that all statements in the batch are executed within a single transaction?Multiple choiceMedium
- Which JDBC feature is not directly supported by batch processing?Multiple choiceHard
- In the context of JDBC batch processing, what is the effect of using setAutoCommit(false) and manually committing the transaction after executeBatch()?Multiple choiceHard
- Why might you choose to use a PreparedStatement in JDBC over a regular Statement?Multiple choiceMedium
- Why does JDBC in a Java application matter in practice?Multiple choiceEasy
- Why do teams use a connection pool in a JDBC application in production code?Multiple choiceMedium
- Which JDBC method is used to execute a query that returns a ResultSet?Multiple choiceEasy
- How can you ensure that a ResultSet's resources are cleaned up even if an exception occurs during processing?Multiple choiceHard
- What does calling commit() on a JDBC connection evaluate to?Multiple choiceMedium
- How does the presence of an index affect INSERT operations on a database table?Multiple choiceMedium
- Why is it important to close a ResultSet object after use?Multiple choiceHard
- In a JDBC transaction, what is the purpose of setting auto-commit to false?Multiple choiceHard
- Why can mapping a joined orders plus order_items result set be trickier than mapping a single products table?Multiple choiceHard
- What should determine whether you add an index to a table?Multiple choiceMedium
- Which of the following SQL statements would be most improved by adding an index to the 'product_id' column of an 'orders' table?Multiple choiceMedium
- How can you handle multiple database updates within a single transaction in JDBC?Multiple choiceHard
- Why does the DriverManager class in JDBC matter in practice?Multiple choiceEasy
- What would be a potential outcome if a ResultSet is not closed after use?Multiple choiceMedium
- Which SQL JOIN type would you use to include all records from the left table and matched records from the right table, inserting NULLs for non-matching rows?Multiple choiceMedium
- How can you handle exceptions when executing a batch if you want to commit only successful statements?Multiple choiceHard
- Which of these is a characteristic of a database transaction?Multiple choiceEasy
- Which of the following is a correct way to use a PreparedStatement to prevent SQL injection in an e-commerce application?Multiple choiceHard
- In JDBC, what should you do if an exception occurs after setting auto-commit to false and before committing?Multiple choiceMedium
- How does using a JOIN affect the result set shape compared to separate queries?Multiple choiceMedium
- Which method is used to check if the ResultSet has more rows?Multiple choiceEasy
- Why might you avoid using an index on a column with a high number of unique values?Multiple choiceMedium