Skip to content
Sharp

SQL for Java Devs interview questions

Batching, Indexes, JDBC, JOINs, PreparedStatements, Repository Pattern

172 questions with answers and explanations · 171 flashcards

Questions (page 4 of 4)

  1. How can you avoid the N+1 query problem when fetching orders and their items in a single transaction?Multiple choiceHard
  2. Which JDBC method is used to execute a SQL SELECT query and retrieve data?Multiple choiceMedium
  3. Which SQL clause is used to view the execution plan of a query in databases?Multiple choiceMedium
  4. Which JDBC method is used to execute a SQL SELECT query?Multiple choiceEasy
  5. Which method is used to add SQL statements to a batch in JDBC?Multiple choiceEasy
  6. What happens to the database state when executeBatch() is called without proper error handling, and one statement fails?Multiple choiceMedium
  7. In terms of performance, why might you choose to use a batch update with PreparedStatement?Multiple choiceMedium
  8. Why does using ResultSet.TYPE_SCROLL_INSENSITIVE when creating a ResultSet matter in practice?Multiple choiceHard
  9. Why is it recommended to use PreparedStatements instead of plain Statements for executing repeated queries?Multiple choiceEasy
  10. Which scenario would benefit most from using JDBC batch processing?Multiple choiceHard
  11. Which JDBC interface provides a way to execute parameterized SQL queries?Multiple choiceEasy
  12. When using a PreparedStatement, which of the following is a primary benefit over a Statement?Multiple choiceEasy
  13. Which JDBC component is responsible for holding data retrieved from a database?Multiple choiceEasy
  14. How can you ensure that two transactions don't interfere with each other in a Java e-commerce application?Multiple choiceHard
  15. Why is a repository method usually smaller than a full business transaction?Multiple choiceHard
  16. Which JDBC feature allows mapping SQL NULL values to Java null when retrieving column values?Multiple choiceHard
  17. Given tables 'customers' and 'orders', which SQL query correctly retrieves customers with their latest order?Multiple choiceHard
  18. How would you explain a key performance advantage of using PreparedStatements in JDBC in an interview?Multiple choiceMedium
  19. In JDBC, how can you optimize the performance of repeated database reads?Multiple choiceMedium
  20. When should you avoid using indexes in a database table?Multiple choiceMedium
  21. Which statement about using PreparedStatements in transactions is true?Multiple choiceMedium
  22. Why might a developer choose to use a PreparedStatement over a Statement in JDBC?Multiple choiceMedium