title: Converting java.sql.Timestamp to java.util.Calendar without losing precision
body: <p>I'm trying to fetch timestamp values from a database, convert them to Calendar, and convert them back to Timestamp, but they lose their precision.</p>
  
  <p>Here's the code to reproduce the problem</p>
  
  <pre><code>import java.sql.Timestamp;
  import java.util.Calendar;
  
  public class Test {
      public static void main(String[] args)
      {
          Timestamp timestamp = new Timestamp(112, 10, 5, 15, 39, 11, 801000000);
          System.out.println("BEFORE "+timestamp.toString());
          Calendar calendar = Calendar.getInstance();
          calendar.setTimeInMillis(timestamp.getTime());
          timestamp = new Timestamp(calendar.getTimeInMillis());
          System.out.println("AFTER "+timestamp.toString());
      }
  }
  </code></pre>
  
  <p>Here is the sample result of conversion</p>
  
  <pre><code>BEFORE 2012-10-18 14:30:13.362001
  AFTER 2012-10-18 14:30:13.362
  </code></pre>
  
  <p>It loses its precision.
  What do I do to keep the decimal value as it is?</p>