• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

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!!
0
Margin_Walker
Asked:
Margin_Walker
  • 3
  • 2
2 Solutions
 
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
 
cmalakarCommented:
There is a getDate() function in ResultSet object..
If the table field is of type Date, then you can use that directly..
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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