I want to generate a code that will automatically take the poll-id..of which the user wishes to view the result of that poll. there's the code:using mysql & java & another thing i wish to use this on a jsp page:
package votepiepack;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import org.jfree.chart.*;
import org.jfree.data.jdbc.*;
import org.jfree.data.general.*;
public class votepie {
/**
* @param args
*/
private PieDataset readData() {
JDBCPieDataset data = null;
String url = "jdbc:mysql://localhost/vote";
Connection con;
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "vote", "vote001");
data = new JDBCPieDataset(con);
String sql = "SELECT option_text, counter FROM VOTE_VOTES WHERE poll-id=1;";
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;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
votepie pd = new votepie();
pd.readData();
//creating the chart
JFreeChart chart = ChartFactory.createPieChart(
"Sample Pie Chart",
pd.readData(),
true, // legend?
true, // tooltips?
false // URLs?
);
// create and display a frame...
ChartFrame frame = new ChartFrame("First", chart);
frame.pack();
frame.setVisible(true);
}
}
as you can see I can view only 1 result at a time.
String sql = "SELECT option_text, counter FROM VOTE_VOTES WHERE poll-id=1;";
but how is it possible to capture the poll-id on which the user wishes to click & show the result of that poll....is it by using "placeholders" if yes how? or any other, please suggest..thanks
ps: donno where to post so posting both on mysql & java forums.