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.getConnectio n(QRURLStr ing, dbProps);
String sql = "SELECT dateValue FROM calypso..hsbcValueDate WHERE dateIdentifier = 'T0'";
Statement stmt1 = dev_connection.createState ment();
ResultSet rs = stmt1.executeQuery(sql.toS tring());
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!!
I have the following piece of code to retreive a date from a sybase database:
try{
Class.forName("com.sybase.
Properties dbProps = new Properties();
dbProps.put("user", "uuuuu");
dbProps.put("password", "ppppp");
dev_connection= DriverManager.getConnectio
String sql = "SELECT dateValue FROM calypso..hsbcValueDate WHERE dateIdentifier = 'T0'";
Statement stmt1 = dev_connection.createState
ResultSet rs = stmt1.executeQuery(sql.toS
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!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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);
}
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 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..
ASKER
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
Apologies for the confusion but thanks for your help as always
Margin Walker
Also, make sure that you shouldn't be using JDateTime instead (notice that "t" is capitalized)