Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5689
  • Last Modified:

Java:Cannot format given Object as a Date

I tried this and:
public void setRec_date(String string) {
                                    
            recDate = (String)dateFormat.format(string);
      }
When I run the program the error is : Cannot format given Object as a Date

Thank you
0
coolgem
Asked:
coolgem
  • 3
  • 2
2 Solutions
 
coolgemAuthor Commented:
also I defined as a class var :
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
      
public void setRec_date(String string) {
                             
          recDate = (String)dateFormat.format(string);
     }
When I run the program the error is : Cannot format given Object as a Date

Thank you
0
 
InteractiveMindCommented:
Can you provide a Date object instead of a String object, to your method?
0
 
InteractiveMindCommented:
If not, then will the data within the String be in a particular format?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
coolgemAuthor Commented:
NO.  Because after the sql execution the field is in a string.
0
 
InteractiveMindCommented:
[Are the sql fields data/times themself? If so, then you can retrieve them as Date objects using either getDate() or (Date)getTimestamp() in the ResultSet class.]
0
 
AutogardCommented:
Coolgem -- did you try my suggestions in your previous question? (http://www.experts-exchange.com/Programming/Q_21878474.html#16858007) What datatype are your dates stored as in the database?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now