• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Sybex Practice Tests 11 - Chapter 11 - Q #11

 
Greenhorn
Posts: 10
3
  • Likes 1
  • 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: 80140
418
  • 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: 10
3
  • 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.
 
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed. Added to the errata.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic