I have made a database containing 4 subject marks and name and roll no. of students. I want to retrieve the data from the access database using prepared statement and then display the bar graph using jfreechart API .This whole retrieval and display of chart is to be done in a servlet..
Note that it is a access made database.
How can I proceed ..Pls answer.Its very urgent.
Follow these steps:
1)Go to the start->Control Panel->Administrative Tools-> data sources.
2)Click Add button and select the driver Microsoft Access Driver(*.mdb).
3)After selecting the driver, click finish button.
4)Then give Data Source Name and click ok button.
5)Your DSN will get created.
6) Restart your tomcat server and run your jsp code.
<%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <%@ page import="org.jfree.chart.ChartFactory" %> <%@ page import="org.jfree.chart.ChartUtilities" %> <%@ page import="org.jfree.chart.JFreeChart" %> <%@ page import="org.jfree.chart.plot.PlotOrientation"%> <%@ page import="org.jfree.data.*" %> <%@ page import="org.jfree.data.jdbc.JDBCCategoryDataset"%> <% String query="SELECT * from chart"; JDBCCategoryDataset dataset=new JDBCCategoryDataset("jdbc:odbc:student", "sun.jdbc.odbc.JdbcOdbcDriver","root","root"); dataset.executeQuery(query); JFreeChart chart = ChartFactory .createBarChart3D( "Test", "Id", "Score", dataset, PlotOrientation.VERTICAL,true, true, false); try { ChartUtilities.saveChartAsJPEG(new File("C:/chart.jpg"), chart, 400, 300); } catch (IOException e){ System.out.println("Problem in creating chart."); } %>
But for above code, you need jfreechart api. It seems that you are having this api.
For more information, visit the following link:
http://www.roseindia.net/jsp/draw-statistical-chart-jsp.shtml
Ads