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

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

Introduction

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

Prototype

public void executeQuery(String query) throws SQLException 

Source Link

Document

Populates the dataset by executing the supplied query against the existing database connection.

Usage

From source file:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java

public static void relatoriosFiliais() {
    String sql = "";

    try {/*from  ww  w . j a v a 2  s.co m*/
        Connection conn = Conexoes.obterConexao();

        JDBCCategoryDataset ds = new JDBCCategoryDataset(conn, sql);

        ds.executeQuery(sql);

        JFreeChart grafico = ChartFactory.createLineChart("Grfico de Disponibilidade", "Filial", "Quantidade",
                ds, PlotOrientation.HORIZONTAL, true, true, true);

    } catch (SQLException | ClassNotFoundException ex) {
        System.err.println(ex.getMessage());
    }
}

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

private static JDBCCategoryDataset generateBarChartDataSet(Connection con, String sql) {
    JDBCCategoryDataset data = null;

    try {/*from  w ww. ja v  a  2  s  . c  o m*/
        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:org.posterita.core.BarChart.java

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

    try {//from w w  w. ja v a 2  s. c o  m
        jdbcDataset.executeQuery(sql);
        this.dataset = jdbcDataset;
    } catch (SQLException e) {
        throw new OperationException(e);
    }
}

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

private JDBCCategoryDataset generateBarChartDataSet(Connection con, String sql) {
    JDBCCategoryDataset data = null;

    try {// w  ww. j  ava  2 s  . c o m
        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  ww .  j  av  a  2 s  .  com*/
        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;
}

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

private CategoryDataset readData() {
    JDBCCategoryDataset jdbccategorydataset = null;
    String s = "jdbc:postgresql://localhost/jfreechartdb";
    try {/*ww w.jav a  2  s. c  om*/
        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;
}