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
coolgemAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
AutogardConnect With a Mentor Commented:
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
 
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
InteractiveMindCommented:
If not, then will the data within the String be in a particular format?
0
 
coolgemAuthor Commented:
NO.  Because after the sql execution the field is in a string.
0
 
InteractiveMindConnect With a Mentor Commented:
[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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.