File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date problem

 
Bill Walker
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get an error that valueOf is not a method of java.sql.Date
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
give this a try:
 
Bill Walker
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats seems to work except I don't want the time attached to it. It's just a date of birth.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic