Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Timestamp to date

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to figure out what a database field stands for,....
I have fields like 00000001153858800000, 0000009223372036854775807 etc.,

I thought this could be a timestamp and tried to get a date out of it
This is the code I am using.
When i put in 1153858800000L, it gives me
Day: 2
Month:6
Year 2006

But when I enter 9223372036854775807, looks like i am way off the mark.
it gives me year:292278994, day :0


public class TimestampTest
{

public static void main(String[] args)
{
//1153858800000L
long startTime =9223372036854775807L ;

Date startDate = new Date(startTime);
int year = startDate.getYear()+1900;

System.out.println("Day: "+startDate.getDay());
System.out.println("Month: "+startDate.getMonth());
System.out.println("Year: "+year);
System.out.println("time : "+startDate.getTime());
System.out.println("Hours : "+startDate.getHours());
System.out.println("Minutes: "+startDate.getMinutes());
System.out.println("Seconds: "+startDate.getSeconds());

}
}
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What platform is it? If it is a common platform, such as MSSQL, Oracle, Sybase, DB2, MySQL (and there are many more that this can work for) then there should be a JDBC driver for it. If you can find one, then get teh JDBC driver add it to you classpath and then you can use it to find out the type of column using the JDBC API.

If there is no JDBC driver, but there is an ODBC driver, then the JDBC ODBC bridge **should** work with the following as well.

For example, on MSSQL, the following will do it:

//register the driver
try
{
Class driver = Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
DriverManager.registerDriver((Driver)driver.newInstance());
}
catch(Throwable e)
{}

//get a connection using the JDBC specific URL
//and a valid username and password
Connection dbconn = DriverManager.getConnection(url, userName, password);

//get the meta data
DatabaseMetaData aMeta = dbconn.getMetaData();

//get the columns where tableName is the name of the table
ResultSet rs = aMeta.getColumns(null, null, tableName, null);

while(rs.next())
{
rs.getString("COLUMN_NAME")); //name of the column
rs.getShort("DATA_TYPE")); //the data type as a java.sql.Type
rs.getString("TYPE_NAME")); //the name of the data type
}

rs.close();

Please note, if the name of the data type doesnt cut it, then use the data type noted above and use the java.sql.Types object to convert it.

This will be much easier than what it looks like you are trying to do. I dont think that the fact that the raw data found, presumably in some query tool, will convert straight off necessarily to a java type. You may in fact be correct that its a timestamp (or maybe not) but the above should tell you asap.

Hope that helps.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why even bother with JDBC? You could just query the catalog directly to find out what data type your field uses.

Tell us which data base it is you are using and someone may tell you the SQL to do this.

(Also, this is not a Java question really. We have a JDBC forum where this is better suited, so I'm moving it there)
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic