Link to home
Start Free TrialLog in
Avatar of Margin_Walker
Margin_Walker

asked on

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!!
Avatar of gatorvip
gatorvip
Flag of United States of America image

What is JDatetime?

Also, make sure that you shouldn't be using JDateTime instead (notice that "t" is capitalized)
ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Margin_Walker
Margin_Walker

ASKER

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);
}
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..

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