Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The quick answer is that you call the constructor with your parameters. In Java: </p> <pre><code>public class Contact { private final String firstName; private final String middleName; private final String lastName; private final Date birthday; public Contact( String firstName, String middleName, String lastName, Date birthday ) { this.firstName = firstName; this.middleName = middleName; this.lastName = lastName; this.birthday = birthday; } … // getters } … inside while loop: contacts.add(new Contact( rs.getString("first_name"), rs.getString("middle_name"), rs.getString("last_name"), new Date(birthday.getTime()) ); </code></pre> <p>I left out the optional birthday for now, we'll add it back in the Scala version.</p> <p>We still have a mutable Contacts list though, so lets look at making it properly immutable. We'll use a Scala list. First, the scala data object:</p> <pre><code>case class Contact( first: String, middle: String, last: String, birthday: Option[Date]) </code></pre> <p>We have optional birthday as part of the type-sig as a bonus.</p> <p>Now lets define a simple extractor method, given a resultSet:</p> <pre><code>def contacts(rs: ResultSet) = { @annotation.tailrec def loop(cs: List[Contact]): List[Contact] = if (!rs.next()) cs else loop( Contact( rs.getString("first_name"), rs.getString("middle_name"), rs.getString("last_name"), Option(rs.getLong("birthday")) ) :: cs) loop(Nil) } </code></pre> <p>This version recursively builds up a singly-linked list of all contacts in your ResultSet. This is immutable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload