hello
I have a database consisting of datetime of type timestamp and memory used of int.
Database(test4.test) consists of
15 2012-02-03 15:14:43
12 2012-05-06 16:17:46
But we are unable to plot a graph showing the errors saying
Exception in thread "main" java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.sql.Date
at org.jfree.data.jdbc.JDBCCategoryDataset.executeQue ry(JDBCCategoryDataset.java: at org.jfree.data.jdbc.JDBCCategoryDataset.executeQue ry(JDBCCategoryDataset.java: at Chart1.main(Chart1.java:26)
Java Result: 1
How to resolve this error.
the following code we have used
import java.sql.*;
import java.io.*;
import org.jfree.ui.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.*;
import org.jfree.data.jdbc.JDBCCategoryDataset;
public class Chart1 {
public static void main(String[] args) throws Exception {
String query = "SELECT * from test";
JDBCCategoryDataset dataset = new JDBCCategoryDataset( "jdbc:mysql://localhost:3306/test4", "com.mysql.jdbc.Driver","root", "root");
dataset.executeQuery(query);
JFreeChart chart = ChartFactory.createLineChart("Test", "Id", "Score", dataset, PlotOrientation.VERTICAL, true, true, false);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
ApplicationFrame f = new ApplicationFrame("Chart");
f.setContentPane(chartPanel);
f.pack();
f.setVisible(true);
}
}
please tel what is the error and how to resolve it