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

  1. Why can JDBC batch processing if not carefully managed become a problem in production code?Multiple choiceMedium
  2. How can you safely execute a user-supplied search term in a SQL query using a PreparedStatement?Multiple choiceMedium
  3. What role does the JDBC DriverManager class play in a Java application?Multiple choiceMedium
  4. Which of the following best describes the role of a placeholder in a PreparedStatement?Multiple choiceEasy
  5. Why might a transaction fail in a JDBC application?Multiple choiceHard
  6. Which SQL keyword is used to combine rows from two or more tables based on a related column?Multiple choiceEasy
  7. Which interface does ResultSet implement?Multiple choiceEasy
  8. Which JDBC interface is responsible for managing database connections?Multiple choiceEasy
  9. How would you explain a placeholder in the context of a PreparedStatement in an interview?Multiple choiceEasy
  10. Which of the following is a key advantage of using PreparedStatement over Statement in JDBC?Multiple choiceEasy
  11. Which SQL statement can you use to create an index on the 'email' column of a 'users' table to speed up search queries?Multiple choiceEasy
  12. How would you explain the return type of the executeBatch() method in JDBC in an interview?Multiple choiceMedium
  13. Which of the following is a direct benefit of using JDBC batch processing for multiple inserts in a database?Multiple choiceEasy
  14. How do you safely extract an integer value from the 'quantity' column in a ResultSet?Multiple choiceMedium
  15. In a JDBC-based e-commerce application using the Repository pattern, what is the primary purpose of a Repository class?Multiple choiceEasy
  16. When analyzing an execution plan with EXPLAIN, which keyword indicates that an index is being used in a query?Multiple choiceHard
  17. How do PreparedStatements improve performance in database operations?Multiple choiceMedium
  18. What are the consequences of not closing a ResultSet in JDBC?Multiple choiceHard
  19. In a manual ORM, what happens if a ResultSet column is missing when mapping to a Java object?Multiple choiceMedium
  20. Why do teams use indexes in a database in production code?Multiple choiceEasy
  21. Which SQL clause is used to combine rows from two or more tables based on a related column?Multiple choiceEasy
  22. Why is it important to use setAutoCommit(false) in JDBC when managing transactions?Multiple choiceMedium
  23. How can you determine the number of rows in a ResultSet?Multiple choiceMedium
  24. What might be a consequence of not closing a PreparedStatement in a database-heavy e-commerce application?Multiple choiceHard
  25. Consider the following code snippet. What is a potential drawback of this JDBC transaction management approach?Multiple choiceHard
  26. Why do teams use PreparedStatements over Statements in JDBC in production code?Multiple choiceMedium
  27. Which JDBC method should you call to ensure all changes in a transaction are discarded?Multiple choiceEasy
  28. How would you explain a common way to iterate through a ResultSet in a Java interview?Multiple choiceEasy
  29. When using JDBC batch processing, which approach can help improve performance for inserts on a database with high write concurrency?Multiple choiceHard
  30. When using transactions in JDBC, what is the consequence of setting auto-commit to false and not explicitly calling commit()?Multiple choiceHard
  31. In JDBC, what is a potential consequence of leaving auto-commit mode enabled during a bulk insert operation?Multiple choiceMedium
  32. Which of the following sequences correctly represents handling a transaction in JDBC?Multiple choiceMedium
  33. Why is it useful to calling rollback() in a JDBC transaction?Multiple choiceEasy
  34. When using JDBC batch processing, which of the following methods is used to execute batched SQL statements?Multiple choiceMedium
  35. Consider the following code snippet. What will happen if one of the statements in the batch fails?Multiple choiceMedium
  36. Why do teams use PreparedStatements over Statements in JDBC in production code?Multiple choiceMedium
  37. When analyzing a query execution plan, which of the following indicates an inefficient use of indexes?Multiple choiceHard
  38. How can you ensure that a JDBC transaction properly handles concurrent updates to prevent lost updates?Multiple choiceHard
  39. Which setting should be adjusted to ensure batch statements are only committed once all are successfully executed?Multiple choiceEasy
  40. Why does the ResultSet in JDBC matter in practice?Multiple choiceEasy
  41. Which JDBC method is used to bind a String parameter to a PreparedStatement?Multiple choiceMedium
  42. Why does using a RIGHT JOIN between two tables, 'suppliers' and 'products', on the result set change runtime behavior?Multiple choiceMedium
  43. Who should usually own the transaction for a checkout that saves the order, inserts items, and updates stock?Multiple choiceMedium
  44. Which method is used to bind an integer parameter to a PreparedStatement?Multiple choiceMedium
  45. Why might using rs.getString() for all column types in a ResultSet be problematic?Multiple choiceHard
  46. When working with a ResultSet, what is the correct way to handle SQLException?Multiple choiceEasy
  47. How would you explain a key benefit of using PreparedStatements for executing complex joins in a large e-commerce database in an interview?Multiple choiceHard
  48. You are using JDBC batch processing to insert a list of products into the database. What is a common issue you might face if you do not properly manage the…Multiple choiceMedium
  49. When combining tables using a JOIN, which JDBC method allows you to safely insert parameter values into your SQL query?Multiple choiceEasy
  50. Which code correctly handle a SQLException when closing a ResultSet?Multiple choiceMedium