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