title: How do I properly get a SQL Datetime back into my Java application?
body: <p>I'm having trouble with retrieving queries from my SQL database. I can get the blasted things <em>added</em> to the database, but I'm having an inordinate amount of difficulties performing the reverse. Three things, in order:</p>
  
  <p>The SQL Table itself:</p>
  
  <pre><code>CREATE TABLE patientInstructions (
      id          INT UNSIGNED AUTO_INCREMENT,
      lastUpdated datetime NOT NULL,
      PatientID          BIGINT UNSIGNED NOT NULL,
      HCPID              BIGINT UNSIGNED NOT NULL,
      OVid               BIGINT UNSIGNED NOT NULL,
      urlLink             VARCHAR(250) NOT NULL,
      linkInstructions    VARCHAR(500) NOT NULL,
      linkName            VARCHAR(100) NOT NULL,
      PRIMARY KEY (id)
  ) AUTO_INCREMENT=1 ENGINE=MyISAM;
  </code></pre>
  
  <p>The method call that is failing (I'm getting -1L instead of the actual data value stored in the database, which is why I know there's a problem in the first place):</p>
  
  <pre><code>public String getLastUpdated(long ovID) throws DBException {
          try {
              return psiDAO.getLastUpdated(ovID);
          } catch (myOwnException e) {
              e.printStackTrace();
              return "-1L";
          }
      }
  </code></pre>
  
  <p>And finally, the method call which is failing:</p>
  
  <pre><code>public String getLastUpdated(long ovId) throws DBException {
          Connection conn = null;
          PreparedStatement ps = null;
          try {
              conn = factory.getConnection();
              ps = conn.prepareStatement("SELECT * FROM patientInstructions"
                      + " WHERE ovId=?");
              ps.setLong(1, ovId);
              ResultSet rs = ps.executeQuery();
              java.util.Date updated = new java.util.Date();
              updated = rs.getTime("lastUpdated");
              return updated.toString();
          } catch (SQLException e) {
              e.printStackTrace();
              throw new DBException(e);
          } finally {
              DBUtil.closeConnection(conn, ps);
          }
      }
  </code></pre>
  
  <p>What Java object matches a SQL Datetime? I've tried rs.getTimestamp, rs.getDate, etc. but haven't had any more success (though I'm not ruling out that I botched those up either). Am I making a mistake transferring the data from the resultset back to Java object?</p>