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 2 of 4)

  1. Which of the following ensures that a JDBC transaction is properly executed from start to finish?Multiple choiceMedium
  2. Given a table 'orders' with columns 'id', 'customer_id', and 'amount', which PreparedStatement correctly retrieves orders for a specific customer, sorted by…Multiple choiceHard
  3. Why can using the Repository pattern to abstract JDBC logic in terms of code maintainability become a problem in practice?Multiple choiceHard
  4. How can you map a ResultSet row to a Java object in a manual ORM implementation?Multiple choiceMedium
  5. Why is it important to close a JDBC Connection, Statement, and ResultSet in a finally block or using try-with-resources?Multiple choiceMedium
  6. Which JDBC object should be used to prevent SQL injection when executing a SQL query with user input?Multiple choiceMedium
  7. Which JDBC object is used to read a large result set efficiently and avoid loading all rows into memory at once?Multiple choiceEasy
  8. What happens if you try to commit a transaction when auto-commit mode is enabled in JDBC?Multiple choiceEasy
  9. During a database transaction in JDBC, which isolation level would prevent phantom reads?Multiple choiceHard
  10. Why is it useful to disabling auto-commit mode in JDBC?Multiple choiceEasy
  11. Which of the following is true about PreparedStatements and SQL query plan caching?Multiple choiceEasy
  12. Why should you avoid concatenating user input directly into SQL queries?Multiple choiceMedium
  13. Why do teams use batch processing with JDBC's addBatch and executeBatch methods in production code?Multiple choiceEasy
  14. What happens if a SQLException is thrown after disabling auto-commit but before explicitly committing?Multiple choiceHard
  15. Which of the following statements about JDBC batch processing is true?Multiple choiceEasy
  16. Why might a LEFT JOIN be more beneficial compared to an INNER JOIN in certain scenarios?Multiple choiceHard
  17. What effect does calling connection.setAutoCommit(true) have in JDBC?Multiple choiceMedium
  18. In which scenario is it beneficial to use an index on the 'email' column of a 'customers' table?Multiple choiceMedium
  19. Why does an e-commerce app eventually need relational persistence instead of only in-memory collections?Multiple choiceEasy
  20. In a JDBC application, how can you ensure that two transactions do not interfere with each other when updating the same row?Multiple choiceHard
  21. Why can using a while(rs.next()) loop without closing the ResultSet become a problem in practice?Multiple choiceHard
  22. In a JDBC application, what is the effect of calling commit() on a Connection object?Multiple choiceHard
  23. In a manual ORM implementation, which approach ensures all necessary fields are mapped from a ResultSet to a Java object?Multiple choiceHard
  24. How does the try-with-resources statement improve the management of JDBC connections?Multiple choiceMedium
  25. In a JDBC result set, which method retrieves the value of a specified column as a Java String?Multiple choiceEasy
  26. Why can not using PreparedStatements in a database-heavy application become a problem in production code?Multiple choiceHard
  27. Which of the following best describes a benefit of using the Repository Pattern with JDBC in Java?Multiple choiceMedium
  28. Why is PreparedStatement the right default for queries like findBySku?Multiple choiceMedium
  29. Which statement correctly sets up a JDBC transaction?Multiple choiceMedium
  30. In JDBC, which method is used to execute a SQL SELECT query and return a ResultSet?Multiple choiceMedium
  31. Which SQL operation is least likely to benefit from an index on the target column?Multiple choiceEasy
  32. Which method would you use to explicitly start a transaction in JDBC?Multiple choiceMedium
  33. What might be a consequence of not setting auto-commit to false when managing transactions in JDBC?Multiple choiceHard
  34. Why does adding an index on a column in terms of write performance matter in practice?Multiple choiceHard
  35. Which method is used to execute a query that returns data in JDBC?Multiple choiceEasy
  36. How would you explain a common issue when using raw JDBC for database connections in a high-traffic e-commerce application in an interview?Multiple choiceHard
  37. In a JDBC transaction, how should you ensure all operations use the same PreparedStatement?Multiple choiceHard
  38. In a high-concurrency environment, which isolation level would you choose to prevent dirty reads but allow non-repeatable reads?Multiple choiceHard
  39. Consider the following code snippet. What will be the result if executeBatch() is called and one of the SQL statements is invalid?Multiple choiceMedium
  40. Which JDBC method is used to revert changes made in the current transaction?Multiple choiceMedium
  41. Why does the ON clause in a SQL JOIN matter in practice?Multiple choiceEasy
  42. Which JDBC feature can be used to map SQL NULL values to Java null?Multiple choiceMedium
  43. Which JDBC object is typically used to execute a static SQL query and return a ResultSet?Multiple choiceEasy
  44. Why do teams use PreparedStatements over plain Statements in JDBC in production code?Multiple choiceEasy
  45. What role does the DriverManager play in a JDBC application?Multiple choiceMedium
  46. When using JDBC, why is it recommended to use a try-with-resources statement?Multiple choiceMedium
  47. Why use JDBC batching when inserting many order items?Multiple choiceEasy
  48. In JDBC, how can you efficiently retrieve a list of orders with their associated customer names using SQL?Multiple choiceMedium
  49. How can you ensure that your JDBC code is resilient to SQL injection attacks?Multiple choiceMedium
  50. How does an index on a column speed up a sequential scan?Multiple choiceHard