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