• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Sybex Practice Tests 11 - Chapter 11 - Q #11

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option D says "The code does not compile due to line s2."

But in code there is no such line with a comment //s2

var url = "jdbc:derby:bunnies";
var sql = "INSERT INTO bunny(name, color) VALUES (?, ?)";
try (var conn = DriverManager.getConnection(url);
  var stmt = conn.prepareStatement(sql)) {  // s1

  stmt.setString(1, "Daisy");
  stmt.setString(2, "Brown");

  stmt.executeUpdate();

  stmt.setString(1, "Cinna");
  stmt.setString(2, "Brown");

  stmt.executeUpdate();
}
 
Marshal
Posts: 72406
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the question show a catch or a finally? Neither is absolutely necessary because this is a try with resources.
 
Andrey Kotelnikov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Does the question show a catch or a finally? Neither is absolutely necessary because this is a try with resources.



There are no catch or finally. They are not necessary here.
Eror is in option D description.
It says about some line with comment  //s2
But there is no line with such a comment in code. Though option D is not correct I think authors missed this comment (//s2) in code.
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic