Solved

Java:Cannot format given Object as a Date

Posted on 2006-06-09
6
5,116 Views
Last Modified: 2008-01-09
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
Comment
Question by:coolgem
  • 3
  • 2
6 Comments
 

Author Comment

by:coolgem
ID: 16873293
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
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16873433
Can you provide a Date object instead of a String object, to your method?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16873453
If not, then will the data within the String be in a particular format?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:coolgem
ID: 16873457
NO.  Because after the sql execution the field is in a string.
0
 
LVL 25

Assisted Solution

by:InteractiveMind
InteractiveMind earned 125 total points
ID: 16873478
[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
 
LVL 8

Accepted Solution

by:
Autogard earned 125 total points
ID: 16875346
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now