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…
Question
Options
- A00001
- BAAAAA
- C00001
- D1
How the community answered
(29 responses)- A10% (3)
- B17% (5)
- C69% (20)
- D3% (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
Community Discussion
9The 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.
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.
Fell for A, but both rows match AAAAA, so getString(1) loops twice.
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.
Option C. rs.getString(1) pulls ColumnA both rows, so you get 00001 then 00002.
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.
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.
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.
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.