aspose file tools*
The moose likes Java in General and the fly likes date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "date problem" Watch "date problem" New topic
Author

date problem

Bill Walker
Greenhorn

Joined: Aug 22, 2002
Posts: 12
I have a string containing date of birth in mmddccyy format. How do I change it to a Date variable so I can insert it into a Date/Time database field?
John Gooch
Greenhorn

Joined: Jun 25, 2002
Posts: 8
Here is some code that works with Oracle 8.1.7
where sSolDate = "2002-02-05"
java.sql.Date d = java.sql.Date.valueOf(sSolDate);
String sInsSol = "INSERT INTO ASFI_SOLICITATION " + "(SOLICITATION_NBR, AMMEND_NBR, RFQ_STATUS,
CONTRACT_OFC_ID, SOLICITATION_DATE) " +
" VALUES (?, ?, ?, ?, ? )";
try
{ PreparedStatement pInsertSol = cSolCon.prepareStatement(sInsSol);
pInsertSol.setString(1, sSolNum);
pInsertSol.setString(2, sAmendNum);
pInsertSol.setString(3, sSolType );
pInsertSol.setString(4, sContractOfc );
pInsertSol.setDate(5, d );
pInsertSol.executeUpdate();
}
catch (SQLException e)
{ System.err.println("Unable to create ASFI_SOLICITATION " + e);
System.exit(1);
}
John Gooch
Greenhorn

Joined: Jun 25, 2002
Posts: 8
Here is some code that works with Oracle 8.1.7
where sSolDate = "2002-02-05"
java.sql.Date d = java.sql.Date.valueOf(sSolDate);
String sInsSol = "INSERT INTO ASFI_SOLICITATION " + "(SOLICITATION_NBR, AMMEND_NBR, RFQ_STATUS,
CONTRACT_OFC_ID, SOLICITATION_DATE) " +
" VALUES (?, ?, ?, ?, ? )";
try
{ PreparedStatement pInsertSol = cSolCon.prepareStatement(sInsSol);
pInsertSol.setString(1, sSolNum);
pInsertSol.setString(2, sAmendNum);
pInsertSol.setString(3, sSolType );
pInsertSol.setString(4, sContractOfc );
pInsertSol.setDate(5, d );
pInsertSol.executeUpdate();
}
catch (SQLException e)
{ System.err.println("Unable to create ASFI_SOLICITATION " + e);
System.exit(1);
}
Bill Walker
Greenhorn

Joined: Aug 22, 2002
Posts: 12
I get an error that valueOf is not a method of java.sql.Date
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

give this a try:
Bill Walker
Greenhorn

Joined: Aug 22, 2002
Posts: 12
Thats seems to work except I don't want the time attached to it. It's just a date of birth.
 
wood burning stoves
 
subject: date problem
 
Similar Threads
Unable to get Date instance in a particular format
PGP (Pretty Good Privacy)
Regarding HttpSession
choices.txt structure.
first date and last date of month