Example usage for org.jfree.data.jdbc JDBCCategoryDataset JDBCCategoryDataset

List of usage examples for org.jfree.data.jdbc JDBCCategoryDataset JDBCCategoryDataset

Introduction

In this page you can find the example usage for org.jfree.data.jdbc JDBCCategoryDataset JDBCCategoryDataset.

Prototype

public JDBCCategoryDataset(Connection connection) 

Source Link

Document

Create a new dataset with the given database connection.

Usage

From source file:org.jfree.chart.demo.JDBCCategoryChartDemo.java

private CategoryDataset readData() {
    JDBCCategoryDataset jdbccategorydataset = null;
    String s = "jdbc:postgresql://localhost/jfreechartdb";
    try {/*w w  w . j  a  va  2  s.  c o  m*/
        Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException classnotfoundexception) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(classnotfoundexception.getMessage());
    }
    try {
        Connection connection = DriverManager.getConnection(s, "jfreechart", "password");
        jdbccategorydataset = new JDBCCategoryDataset(connection);
        String s1 = "SELECT * FROM CATEGORYDATA1;";
        System.out.println("Once...");
        jdbccategorydataset.executeQuery(s1);
        System.out.println("Again...");
        jdbccategorydataset.executeQuery(s1);
        System.out.println("Done.");
        connection.close();
    } catch (SQLException sqlexception) {
        System.err.print("SQLException: ");
        System.err.println(sqlexception.getMessage());
    } catch (Exception exception) {
        System.err.print("Exception: ");
        System.err.println(exception.getMessage());
    }
    return jdbccategorydataset;
}

From source file:org.posterita.core.BarChart.java

public void getDataSetFromSQL(String sql) throws OperationException {
    JDBCCategoryDataset jdbcDataset = new JDBCCategoryDataset(DB.getConnectionRO());

    try {/*from   w  w  w. j  a va  2  s.co m*/
        jdbcDataset.executeQuery(sql);
        this.dataset = jdbcDataset;
    } catch (SQLException e) {
        throw new OperationException(e);
    }
}

From source file:com.sun.portal.os.portlets.PortletChartUtilities.java

private static JDBCCategoryDataset generateBarChartDataSet(Connection con, String sql) {
    JDBCCategoryDataset data = null;//from w  w w .  j a v a 2s  .  c om

    try {
        data = new JDBCCategoryDataset(con);
        data.executeQuery(sql);
        con.close();
    } catch (SQLException e) {
        System.err.print("SQLException: ");
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.print("Exception: ");
        System.err.println(e.getMessage());
    }
    return data;
}

From source file:com.sun.portal.os.portlets.ChartServlet.java

private JDBCCategoryDataset generateBarChartDataSet(Connection con, String sql) {
    JDBCCategoryDataset data = null;/*  ww w  .  j  ava 2 s .c  o m*/

    try {
        data = new JDBCCategoryDataset(con);
        data.executeQuery(sql);
        con.close();
    } catch (SQLException e) {
        System.err.print("SQLException: ");
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.print("Exception: ");
        System.err.println(e.getMessage());
    }
    return data;
}

From source file:fr.crnan.videso3d.ihm.PLNSPanel.java

private JToolBar createToolbar() {
    JToolBar toolbar = new JToolBar();

    JButton newGraph = new JButton("Nouveau");
    newGraph.addActionListener(new ActionListener() {

        @Override/*from   w  w w . j  a v  a 2 s.  co m*/
        public void actionPerformed(ActionEvent e) {
            PLNSChartCreateUI chartCreator = new PLNSChartCreateUI(PLNSPanel.this);
            JFreeChart chart = null;
            try {
                if (chartCreator.showDialog(PLNSPanel.this)) {
                    switch (chartCreator.getChartType()) {
                    case 0://XY
                        JDBCXYDataset dataset = new JDBCXYDataset(plnsAnalyzer.getConnection());
                        dataset.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createXYAreaChart(chartCreator.getChartTitle(),
                                chartCreator.getAbscissesTitle(), chartCreator.getOrdonneesTitle(), dataset,
                                PlotOrientation.VERTICAL, false, true, false);
                        break;
                    case 1://Pie
                        JDBCPieDataset dataset1 = new JDBCPieDataset(plnsAnalyzer.getConnection());
                        dataset1.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createPieChart3D(chartCreator.getChartTitle(), dataset1, false,
                                true, false);
                        break;
                    case 2://Category
                        JDBCCategoryDataset dataset2 = new JDBCCategoryDataset(plnsAnalyzer.getConnection());
                        dataset2.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createBarChart(chartCreator.getChartTitle(),
                                chartCreator.getAbscissesTitle(), chartCreator.getOrdonneesTitle(), dataset2,
                                PlotOrientation.VERTICAL, false, true, false);
                        break;
                    default:
                        break;
                    }
                }
            } catch (SQLException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(PLNSPanel.this,
                        "<html>L'excution de la requte a chou :<br />" + e1 + "</html>",
                        "Impossible de crer le graphique", JOptionPane.ERROR_MESSAGE);
            }
            if (chart != null)
                addChart(chart);

        }
    });

    toolbar.add(newGraph);

    JButton retile = new JButton("Rarranger");
    retile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            desktop.tile(true);
        }
    });
    toolbar.add(retile);

    return toolbar;
}