title: How Do I Insert system time Into Ms Access Using Java?
body: <p>I have just created a simple Student Registration Form using Java(Netbeans). It has several columns to enter the students' data such as regNo, name, address, etc and a Insert button which inserts the data into the table created in MS Access.It works fine.But I need to store the time when a user fills that form.It means when a user fills that form, the system time should be captured and stored in the table for each entry(each tuple). So I want to know how to get the system time and insert into MS Access database.I found the following code.But I don't know how to pass the time captured by the code to the database.I have already created the field for enter the time in the database.</p>
  
  <pre><code>Calendar cal = Calendar.getInstance();
  java.util.Date currentTime = cal.getTime();
  </code></pre>
  
  <p>This is the code I wrote to pass time to the table.....</p>
  
  <pre><code>ps = con.prepareStatement("insert into RegInfo(RegNo,StudName,Address,"
                 + "Telephone,Stream,RegDate,Time) values(?,?,?,?,?,?,?)");
  ps.setLong(6,currentTime.getTime());
  </code></pre>
  
  <p>I used your code Razvan. It is working really good but it doesn't insert the Time into the table......("System.out.println" is working properly).....</p>
  
  <pre><code> final String t1 = "hh:mm:ss";
   final DateFormat df = new SimpleDateFormat(t1);
   final String formattedTime = df.format(new java.util.Date());
   ps.setString(7, formattedTime);
   System.out.println("formattedTime "+formattedTime);
  </code></pre>