Convert String to JDatetime

Hi Experts,

I have the following piece of code to retreive a date from a sybase database:
try{
   Class.forName("com.sybase.jdbc2.jdbc.SybDriver");            
   Properties dbProps = new Properties();      
   dbProps.put("user", "uuuuu");
   dbProps.put("password", "ppppp");      
   dev_connection= DriverManager.getConnection(QRURLString, dbProps);
   String sql = "SELECT dateValue FROM calypso..hsbcValueDate WHERE dateIdentifier = 'T0'";
   Statement stmt1 = dev_connection.createStatement();
   ResultSet rs = stmt1.executeQuery(sql.toString());
   while (rs.next())
   {
      strValDate = rs.getString(1);
   }
}catch(Exception e){
      System.out.print(e);
}

JDatetime valDate = (JDatetime)strValDate:
--------------------------------------------------------
but i get the following cast error:
Cannot convert String to JDatetime

Can you help me retreive this value as a JDatetime please!!

Thanks guys!!
Margin_WalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gatorvipCommented:
What is JDatetime?

Also, make sure that you shouldn't be using JDateTime instead (notice that "t" is capitalized)
0
cmalakarCommented:
You cannot typecast directly from one object to another..

unless they have subclass - super class (is a ) relation ship.

I think you may have to create the JDatetime from the strValDate manually..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cmalakarCommented:
There is a getDate() function in ResultSet object..
If the table field is of type Date, then you can use that directly..
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Margin_WalkerAuthor Commented:
Guys thanks for your help but Ive figured it out with the below:

try{
      rSet = sCalypso.executeQuery(sql);
      while (rSet.next())
      {
            JDatetime date1 = new JDatetime(rSet.getDate(1));
      }      
}catch(Exception e){
      System.out.print(e);
}
0
cmalakarCommented:
My Comments...

>> I think you may have to create the JDatetime from the strValDate manually..
>> There is a getDate() function in ResultSet object..

Exactly matches the solution...
How can it be closed, without accepting my comment.. as the right answer..

0
Margin_WalkerAuthor Commented:
I see cmalakars point but my question related to casting the resultset to a JDatetime. I am aware of the getDate() function from a ResultSet.  My resolution was to pass the date from the resultset to the JDatetime constructor to create a new JDatetime which is an object created by a developer in my company.

Apologies for the confusion but thanks for your help as always

Margin Walker
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.