尝试通过JSP/Servles使用JFreeChart; JDBCCategoryDataset和CategoryDataset的问题 [英] Trying to use JFreeChart using JSP/Servles; issues with JDBCCategoryDataset and CategoryDataset

查看:89
本文介绍了尝试通过JSP/Servles使用JFreeChart; JDBCCategoryDataset和CategoryDataset的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到数据库并在servlet中执行查询.我正在按照这个示例 JFreeChart示例.如果您查看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!

推荐答案

因为

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆