Selenium Database Management & SQL 3 — Questions and Answers
Question 1: Which JDBC method retrieves the value of a specific column from a ResultSet by its column name?
- resultSet.getColumn("name")
- resultSet.fetchValue("name")
- resultSet.getString("name") (Correct answer)
- resultSet.readField("name")
Correct answer: resultSet.getString("name")
ResultSet.getString("columnName") returns the string value of the specified column in the current row.
Question 2: A Selenium framework uses a TestNG @DataProvider backed by a database. Which SQL clause would you add to return only active test cases?
- LIMIT active=1
- WHERE is_active = 1 (Correct answer)
- FILTER is_active = TRUE
- SELECT ACTIVE
Correct answer: WHERE is_active = 1
The WHERE clause with a boolean condition filters rows to only those where is_active equals 1 (true).
Question 3: What does the SQL JOIN keyword accomplish when used in a Selenium test data query?
- Merges two database connections
- Appends new rows to a table
- Combines rows from two tables based on a related column (Correct answer)
- Duplicates a table structure
Correct answer: Combines rows from two tables based on a related column
JOIN combines rows from multiple tables where a common column value matches, allowing retrieval of related test data.
Question 4: During Selenium end-to-end testing, you need to verify a user's order status in the database after checkout. Which SQL aggregate function counts the number of orders?
- SUM()
- AVG()
- COUNT() (Correct answer)
- MAX()
Correct answer: COUNT()
COUNT() returns the number of rows matching the query criteria, useful for verifying how many orders were created.
Question 5: A Selenium test modifies an existing record via the UI and then queries the database. Which SQL statement retrieves the updated value?
- INSERT INTO
- UPDATE ... SET
- SELECT ... WHERE (Correct answer)
- ALTER TABLE
Correct answer: SELECT ... WHERE
SELECT with a WHERE clause fetches the current value of a row, allowing the test to assert the UI change was persisted.
Question 6: When configuring a JDBC connection in a Selenium project, what does the connection URL component 'jdbc:mysql://localhost:3306/testdb' specify?
- Driver class name, host, port, and schema (Correct answer)
- Username, password, and encryption method
- Connection pool size and timeout
- SQL dialect and character encoding
Correct answer: Driver class name, host, port, and schema
The JDBC URL format specifies the driver protocol, host address, port number, and target database schema name.
Question 7: Which SQL constraint guarantees that a column used as a test record identifier never contains duplicate values?
- NOT NULL
- DEFAULT
- UNIQUE (Correct answer)
- CHECK
Correct answer: UNIQUE
The UNIQUE constraint enforces that all values in a column are distinct, preventing duplicate identifiers.
Which JDBC method retrieves the value of a specific column from a ResultSet by its column name?