尝试通过 JSP/Servles 使用 JFreeChart;JDBCCategoryDataset 和 CategoryDataset 的问题 [英] Trying to use JFreeChart using JSP/Servles; issues with JDBCCategoryDataset and CategoryDataset
问题描述
我正在尝试连接到数据库并在 servlet 中执行查询.我正在关注这个例子 JFreeChart Example.如果您查看 readData()
方法,当它最初是 JDBCCategoryDataset
时,它返回一个 CategoryDataset
.我收到一个错误,直到我将它转换为 CategoryDataset
.当我运行代码时,它不起作用,告诉我它无法投射.任何帮助将不胜感激!
i am trying to connect to a database and execute a query in a servlet. I am following this example JFreeChart Example. If you look at the readData()
method, it returns a CategoryDataset
when it originally was a JDBCCategoryDataset
. I get an error until i cast it do a CategoryDataset
. When i run the code, it doesn't work, telling me it cannot cast. Any help would be much appreciated!
推荐答案
因为 JDBCCategoryDataset
实现了CategoryDataset
接口,赋值时不需要强制转换:CategoryDataset data = readData();
我从下面概述的 readData()
的变体中得到以下图表.我怀疑你有另一个问题.
Because JDBCCategoryDataset
implements the CategoryDataset
interface, no cast should be required in the assignment: CategoryDataset data = readData();
I get the following chart from the variation of readData()
outlined below. I suspect that you have another problem.
private CategoryDataset readData() {
JDBCCategoryDataset data = null;
Connection con;
try {
con = DriverManager.getConnection("jdbc:h2:mem:test", "", "");
data = new JDBCCategoryDataset(con);
String sql = "select TYPE_NAME, PRECISION "
+ "from INFORMATION_SCHEMA.TYPE_INFO "
+ "where PRECISION BETWEEN 1 AND 12";
data.executeQuery(sql);
con.close();
}
…
return data;
}
这篇关于尝试通过 JSP/Servles 使用 JFreeChart;JDBCCategoryDataset 和 CategoryDataset 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!