
how to create a bar chart from values of the database and the string value should be the entities of the database??plzz help..needed badly..

Here is a code that retrieves the data from the database and create a bar chart from the values.
import java.io.*;
import java.sql.*;
import org.jfree.data.*;
import org.jfree.data.category.*;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.plot.PlotOrientation;
public class Chart{
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("SELECT * from result");
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
while(rs.next()){
dataset.setValue(rs.getInt("result"), "Marks", rs.getString("name"));
}
JFreeChart chart =ChartFactory.createBarChart3D("Test", "Name", "Marks",
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.");
}
}
}