Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 79022
375
  • 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: 41851
904
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic