Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My advice:</p> <ul> <li><strong>Don't</strong> write a generic DAO; Generic classes come back to bite you when you realise they don't quite do what you need in a specific situation and often end up growing in complexity to cover the ever-increasing array of use-cases. Better to code application specific DAOs and then attempt to generify any common behaviour later on.</li> <li>Consider using <a href="http://static.springsource.org/spring/docs/2.0.x/reference/jdbc.html" rel="nofollow noreferrer">Spring JDBC</a> to write app-specific DAOs but in a much more compact and less error-prone fashion than JDBC. Also, unlike Hibernate, Spring JDBC only acts a thin wrapper around raw JDBC giving you finer grained control and more visibility.</li> </ul> <p><strong>Example</strong></p> <pre><code>// Create or inject underlying DataSource. DataSource ds = ... // Initialise Spring template, which we'll use for querying. SimpleJdbcTemplate tmpl = new SimpleJdbcTemplate(ds); // Create collection of "Role"s: The business object we're interested in. Set&lt;Role&gt; roles = new HashSet&lt;Role&gt;(); // Query database for roles, use row mapper to extract and create // business objects and add to collection. If an error occurs Spring // will translate the checked SQLException into an unchecked Spring // DataAccessException and also close any open resources (ResultSet, Connection). roles.addAll(tmpl.query("select * from Role", new ParameterizedRowMapper&lt;Role&gt;() { public Role mapRow(ResultSet resultSet, int i) throws SQLException { return new Role(resultSet.getString("RoleName")); } })); </code></pre>
    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.
 

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