The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

How to select time from timestamp???

Posted by Thabaniz on September 13, 2000 at 8:00 AM

I'm trying to select time(i.e. hh:mm) from a database field called serviceid which is of type timestamp and display it together with other fields.

Here is my code below:

import java.sql.*;

public boolean isRetrieveCallsDetails()
{
try
{
theJoinDatastore = new ServiceCallsDetails.JoinDatastore();
theJoinDatastore.connect("vernonz", "vdadlz");
theJoinDatastore.setAutoCommit(true);

theJoin = new ServiceCallsDetails.Join();

int i = 0;

theJoinManager = new ServiceCallsDetails.JoinManager();

theJoinManager.setXserrefno(serrefno);

theJoinManager.open("ORDER BY SERREFNO");

while(theJoinManager.fetchNext())
{
ServiceCallsDetails.Join theJoin = theJoinManager.element();

System.out.println( theJoin.getSerrefno());
System.out.println( theJoin.getSerdate());
System.out.println( theJoin.getServiceid());
System.out.println( theJoin.getSercomments().trim());
System.out.println( theJoin.getSerpartsusko().trim());
System.out.println( theJoin.getSitename().trim());
System.out.println( theJoin.getEmplastname().trim());
i++;
}
if (i < 1)
{ System.out.println("No data was retrieved-Criteria not met");
theJoinManager.close();
theJoinDatastore.disconnect();
return false;
}
// Selecting time(i.e.hh:mm) from Serviceid field which is of type timestamp for display
java.sql.Timestamp iServiceid;

Calendar cal = Calendar.getInstance();
cal.setTime(iServiceid);

int min = cal.get(Calendar.MINUTE);
int hours = cal.get(Calendar.HOUR);

theJoinManager.close();
theJoinDatastore.disconnect();
return true;
}
catch (Throwable s)
{
System.out.println("An error has occurred..." + s.getMessage());
System.out.println("The print stack trace is as follows...");
s.printStackTrace();
return false;
}
}

Your help will be very much appreciated!!!



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us