PROBLEM with dates from database in a table

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
anibanm
Posts: 12
Joined: Thu May 17, 2007 4:12 pm

PROBLEM with dates from database in a table

Post by anibanm » Fri Jun 22, 2007 9:40 am

I've a problem with the dates.

I've an access database and one of its fields is defined as date/hour.
I've built a table and my problem is that only displays date and no hour.


I tried to implement the code following:

public Class getColumnClass(int c) {
if (c==1) return Minute.class;
if ((c==2)|(c==3)|(c==5)|(c==6)|(c==8)|(c==9)|(c==11)|(c==12))
return Integer.class;
return getValueAt(0,c).getClass();

}

but it doesnt't do well.

2003-03-30 01:50:00.0
2003-03-30 03:00:00.0 ¡It doesn't write 2003-03-30 02:00:00.0!

How can I solve it?

Thank's

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Jun 22, 2007 9:42 am

I don't understand the question.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

anibanm
Posts: 12
Joined: Thu May 17, 2007 4:12 pm

Post by anibanm » Fri Jun 22, 2007 10:01 am

Hello,

I' ve created a dataset from a DB access

public XYDataset createDataset(int min, int max) throws SQLException {
JDBCXYDataset data = null;

try
{
Driver d = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
}
catch (Exception e)
{
System.out.println(e);

}

// GET CONNECTION
Connection con = null;


try
{
String db = "BD";


String url = "jdbc:odbc:Practica;DBQ=" + db;

con = DriverManager.getConnection(url,"","");
data = new JDBCXYDataset(con);

String sql = "SELECT date,v1,v2 FROM a where (ID>="+ min+") and (ID<="+max+")";

data.executeQuery(sql);

con.close();
}
catch(Exception e)
{
System.out.println(e);

}
this.series = new XYSeries("ana");
for (int i = 0; i < data.getItemCount(); i++) {
this.series.add(data.getXValue(0,i),data.getYValue(0,i));
}

return data;
}




data.getXValue(0,i) return double. Then how can I get the date of index i.

Thank's

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Jun 22, 2007 10:27 am

The double that it returns should be the number of milliseconds since 1-Jan-1970.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

anibanm
Posts: 12
Joined: Thu May 17, 2007 4:12 pm

Post by anibanm » Mon Jun 25, 2007 9:50 am

Hello, I found an strange behaviour


Calendar cal = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal= new java.util.GregorianCalendar(2003,2,30,1,50,0) ;
cal2= new java.util.GregorianCalendar(2003,2,30,2,0,0) ;

System.out.println(new Minute(new Date(cal.getTimeInMillis())));
System.out.println(new Minute(new Date(cal2.getTimeInMillis())));


The result is:
Sun Mar 30 01:50:00 CET 2003
Sun Mar 30 03:00:00 CEST 2003 but it should be Sun Mar 02:00:00 2003

What is it happening?
Thank's

Tom
Posts: 32
Joined: Mon Dec 11, 2006 2:50 pm

Post by Tom » Mon Jun 25, 2007 10:31 am

Dont know if that helps but did you notice that the second calendar has summertime on and the first does not? thats why the second time is one hour late... don't know why that happens, but maybe you schould review your code and set the
locales properly...

Tom

Locked