nerdexam
CIW

1D0-441 · Question #162

Consider the following code fragment: 1. Statement s = conn.createStatement(); 2. 3. s.executeUpdate(CREATE TABLE MyTable ( + 4. ColumnA CHAR(5), + 5. ColumnB CHAR(5))); 6. 7. s.executeUpdate(INSERT…

The correct answer is C. 00001. Exam Questions, Study Guides, Practice Tests. Lead the way to help you pass any IT Certification exams, 100% Pass Guaranteed or Full Refund. Especially Cisco, CompTIA, Citrix, EMC, HP, Oracle, VMware, Juniper, Check Point, LPI, Nortel, EXIN and so on. Our Slogan: First Test…

R80 Architecture and Unified Policy Management

Question

Consider the following code fragment: 1. Statement s = conn.createStatement(); 2. 3. s.executeUpdate(CREATE TABLE MyTable ( + 4. ColumnA CHAR(5), + 5. ColumnB CHAR(5))); 6. 7. s.executeUpdate(INSERT INTO MyTable VALUES ( + 8. '00001', 'AAAAA'); 9. s.executeUpdate(INSERT INTO MyTable VALUES ( + 10. '00002', 'AAAAA'); 11. 12. ResultSet rs = s.executeQuery(SELECT * FROM MyTable + 13. WHERE ColumnB = 'AAAAA'); 14. while(rs.next()) 15. System.out.println(rs.getString(1)); Assume that variable conn references a valid and open Connection object, and that the database does not already contain a table named MyTable. Which output is generated?

Options

  • A00001
  • BAAAAA
  • C00001
  • D1

How the community answered

(29 responses)
  • A
    10% (3)
  • B
    17% (5)
  • C
    69% (20)
  • D
    3% (1)

Explanation

Exam Questions, Study Guides, Practice Tests. Lead the way to help you pass any IT Certification exams, 100% Pass Guaranteed or Full Refund. Especially Cisco, CompTIA, Citrix, EMC, HP, Oracle, VMware, Juniper, Check Point, LPI, Nortel, EXIN and so on. Our Slogan: First Test, First Pass. Help you to pass any IT Certification exams at the first try. You can reach us at any of the email addresses listed below. Any problems about IT certification or our products, you could rely upon us, we will give you satisfactory answers in 24 hours.

Topics

#JDBC#SQL query#ResultSet iteration#Java database

Community Discussion

9
Dervla O.Dervla O.Apr 16, 2026

The answer is C, both rows printed on separate lines, 00001 then 00002, because the WHERE clause matches every row in the table and getString(1) pulls the first column for each iteration of the loop. The trap here is option A, which tempts you into thinking only one row comes back, so read the loop carefully before you commit.

23
Wesley A.Wesley A.Apr 17, 2026

Solid breakdown, and the other angle worth burning into memory is that getString(1) uses 1-based indexing, not 0-based like a Java array, so if the question ever swaps in getString(0) the whole thing throws a SQLException and none of those answer choices apply.

0
Prof. SaraProf. SaraMar 12, 2026

Fell for A, but both rows match AAAAA, so getString(1) loops twice.

4
Dervla O.Dervla O.Mar 14, 2026

The loop count is a red herring once you realize the real trap is that getString(1) is 1-indexed in JDBC but 0-indexed in most everything else the candidate has touched all week, so the first instinct is always off by one before they even think about row count.

0
Wesley A.Wesley A.Mar 22, 2026

Option C. rs.getString(1) pulls ColumnA both rows, so you get 00001 then 00002.

4
Brenda K.Brenda K.Apr 1, 2026

Clock says do not overthink this one, it is a straight read on what getString(1) returns. Column 1 is ColumnA, which holds '00001' and '00002', so the loop prints both values starting with 00001, making A the clear call here, and you should bank the saved seconds on the harder JDBC questions later in the section.

-2
Prof. SaraProf. SaraApr 1, 2026

Brenda, the trap here is that getString(1) maps to position 1 in the SELECT list, not necessarily ColumnA in the table, so if the query selects ColumnB before ColumnA the output sequence flips and the behavior matches option C. Column order in the result set is defined by the query, not by the table definition.

0
Ola B.Ola B.Apr 11, 2026

I have been going back and forth on this one but I keep landing on A and here is why. The query filters on ColumnB equals AAAAA, so both rows match, and rs.getString(1) pulls the first column, which is ColumnA. That means you get the values from ColumnA printed out, which are 00001 and 00002 on separate lines. If you want to convince yourself, spin up a quick H2 or MySQL sandbox, paste that logic in, and watch it print exactly those two strings, one per line.

-2
Wesley A.Wesley A.Apr 13, 2026

Ola, the catch is that rs.getString(1) returns the first column in the SELECT list, not the first column in the table, so if the query selects ColumnB before ColumnA, you get AAAAA printed twice, which is C.

0
Full 1D0-441 Practice