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

  1. Why is it important to disable auto-commit mode for a JDBC transaction when performing multiple updates?Multiple choiceEasy
  2. How can JDBC transactions help maintain data integrity during an e-commerce checkout process?Multiple choiceMedium
  3. What would be the effect of not closing a PreparedStatement in a Java application?Multiple choiceMedium
  4. In JDBC, how do you ensure that SQL injection is prevented when executing a query that searches for a user by email?Multiple choiceMedium
  5. Why do teams use SQL JOINs to fetch relational data in a single query in production code?Multiple choiceMedium
  6. What should a repository method mainly encapsulate?Multiple choiceEasy
  7. How can you prevent the N+1 query problem when retrieving a list of orders with their customer details?Multiple choiceMedium
  8. How can using a PreparedStatement benefit a Java application that frequently executes the same query with different parameters?Multiple choiceMedium
  9. What does a RIGHT JOIN between two tables evaluate to?Multiple choiceMedium
  10. When using JDBC, why is it crucial to handle SQLExceptions properly?Multiple choiceHard
  11. 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
  12. When using JDBC, which method ensures a SQL query is executed as a transaction?Multiple choiceMedium
  13. How does a PreparedStatement mitigate the risk of SQL injection?Multiple choiceMedium
  14. Why would you choose to use PreparedStatement over Statement in JDBC?Multiple choiceMedium
  15. Why is it important to handle SQLExceptions in JDBC properly?Multiple choiceMedium
  16. In JDBC, what is the primary advantage of using a PreparedStatement over a regular Statement?Multiple choiceMedium
  17. Which transaction isolation level in most JDBC databases is the default in Java?Multiple choiceEasy
  18. Why does the Repository Pattern in a Java application using JDBC for database operations matter in this design?Multiple choiceEasy
  19. What method should you use to move the cursor to the first row of a ResultSet object?Multiple choiceEasy
  20. What does an INNER JOIN between two tables on a foreign key evaluate to?Multiple choiceEasy
  21. In the context of JDBC, what is the best approach to handle exceptions to ensure reliable database interactions?Multiple choiceHard
  22. When extracting a 'price' column from a ResultSet, which method should be used to ensure the value is retrieved as a double?Multiple choiceMedium
  23. Why does encapsulating JDBC logic within a Repository when following a layered architecture help in practice?Multiple choiceMedium
  24. In a one-to-many relationship, how is the 'many' side typically represented in Java?Multiple choiceEasy
  25. In a JDBC batch process, how can you ensure that all statements in the batch are executed within a single transaction?Multiple choiceMedium
  26. Which JDBC feature is not directly supported by batch processing?Multiple choiceHard
  27. In the context of JDBC batch processing, what is the effect of using setAutoCommit(false) and manually committing the transaction after executeBatch()?Multiple choiceHard
  28. Why might you choose to use a PreparedStatement in JDBC over a regular Statement?Multiple choiceMedium
  29. Why does JDBC in a Java application matter in practice?Multiple choiceEasy
  30. Why do teams use a connection pool in a JDBC application in production code?Multiple choiceMedium
  31. Which JDBC method is used to execute a query that returns a ResultSet?Multiple choiceEasy
  32. How can you ensure that a ResultSet's resources are cleaned up even if an exception occurs during processing?Multiple choiceHard
  33. What does calling commit() on a JDBC connection evaluate to?Multiple choiceMedium
  34. How does the presence of an index affect INSERT operations on a database table?Multiple choiceMedium
  35. Why is it important to close a ResultSet object after use?Multiple choiceHard
  36. In a JDBC transaction, what is the purpose of setting auto-commit to false?Multiple choiceHard
  37. Why can mapping a joined orders plus order_items result set be trickier than mapping a single products table?Multiple choiceHard
  38. What should determine whether you add an index to a table?Multiple choiceMedium
  39. 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
  40. How can you handle multiple database updates within a single transaction in JDBC?Multiple choiceHard
  41. Why does the DriverManager class in JDBC matter in practice?Multiple choiceEasy
  42. What would be a potential outcome if a ResultSet is not closed after use?Multiple choiceMedium
  43. 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
  44. How can you handle exceptions when executing a batch if you want to commit only successful statements?Multiple choiceHard
  45. Which of these is a characteristic of a database transaction?Multiple choiceEasy
  46. Which of the following is a correct way to use a PreparedStatement to prevent SQL injection in an e-commerce application?Multiple choiceHard
  47. In JDBC, what should you do if an exception occurs after setting auto-commit to false and before committing?Multiple choiceMedium
  48. How does using a JOIN affect the result set shape compared to separate queries?Multiple choiceMedium
  49. Which method is used to check if the ResultSet has more rows?Multiple choiceEasy
  50. Why might you avoid using an index on a column with a high number of unique values?Multiple choiceMedium