Advertisement

04.11.2006 at 08:20PM PDT, ID: 21810740
[x]
Attachment Details

How to convert java.util.Date to java.sql.Date or java.sql.Timestamp

Asked by akamauu in Java Programming Language

Tags: date, convert

I have a java.util.Date object stored in one of my objects and I want to insert it into a MS Access database.

patient.getPtDOB() returns a java.util.Date object.  I initially thought that I need to convert it to a java.sql.Date object in order to insert it into my database, but I understand that java.sql.Date does not contain time data.  So, should I convert it to java.sql.Date or java.sql.Timestamp?  Also, how do I do the conversion?

Thank you for your help!!!


***************************
Here is my code:

PreparedStatement ps = null;
String ptFName = patient.getPtFName();
String ptMName = patient.getPtMName();
String ptLName = patient.getPtLName();
Date ptDOB = patient.getPtDOB();

String insert = "INSERT INTO PATIENT (F_NAME, M_NAME, L_NAME, DOB) " + "VALUES (?, ?, ?, ?)";
ps = conn.prepareStatement(insert);
ps.setString(1, ptFName);
ps.setString(2, ptMName);
ps.setString(3, ptLName);
ps.setDate(4, ptDOB);
ps.executeUpdate();
ps.close();Start Free Trial
[+][-]04.11.2006 at 08:28PM PDT, ID: 16433205

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2006 at 08:41PM PDT, ID: 16433244

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: date, convert
Sign Up Now!
Solution Provided By: objects
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.12.2006 at 12:47AM PDT, ID: 16434001

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.12.2006 at 06:44AM PDT, ID: 16435988

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.12.2006 at 06:51AM PDT, ID: 16436062

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.12.2006 at 07:17AM PDT, ID: 16436321

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.12.2006 at 03:26PM PDT, ID: 16441179

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32