hi guys..........this is the code I'm trying to run

package dbpack;

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 chartdb {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //private void  readData()
    //}
        
    private PieDataset readData()        {
            JDBCPieDataset data = null;
            String url = "jdbc:mysql://localhost/jfreechartdb";
            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, "jfreechart", "password");
            data = new JDBCPieDataset(con);
            String sql = "SELECT * FROM PIEDATA1;";
            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;
            }
}
}

this is code where I want to get data from MySQL & show it on "jfreechart". but I'm getting a error

Syntax error on token(s), misplaced construct(s)
    Syntax error, insert ";" to complete BlockStatements

    at dbpack.chartdb.main(chartdb.java:20)

on this line
private PieDataset readData() {

the error still exists if I include ";" after readdata()

can you please help me regarding this. I'm lost & confused

String sql = "SELECT * FROM PIEDATA1;";

take out that semi-column, their are automaticaly inserted by driver

I believe this may be your problem

public static void main(String[] args) {
        // TODO Auto-generated method stub
        //private void  readData()
    //}
        
    private PieDataset readData()        {

Did you really mean to comment out the } at the end of your main method? Somehow I don't think so.

String sql = "SELECT * FROM PIEDATA1;";

take out that semi-column, their are automaticaly inserted by driver

which colon you are talking about? 1st one I presume.........

& as for he 2nd suggestion, yes I commented that on purpose. as the readdata() is inside main()...........please tell me whats going wrong here.


If I remove 1 "}" at the end as I think there is an extra. the above error is not there anymore but its showing another one:

Syntax error, insert "}" to complete MethodBody

    at dbpack.chartdb.main(chartdb.java:15)

on this line............. public static void main(String[] args) {

Your code is messy. You should either call and execute commands in main method and remove private PieDataset readData() this method. Or from main method make call for the other one private PieDataset readData() which you place outside main method as you wanted previously by seing that bracklet commented out

You cannot define a method inside another method - and that is what your code is trying to do.

& as for he 2nd suggestion, yes I commented that on purpose. as the readdata() is inside main()...........please tell me whats going wrong here.


If I remove 1 "}" at the end as I think there is an extra. the above error is not there anymore but its showing another one:

Syntax error, insert "}" to complete MethodBody

    at dbpack.chartdb.main(chartdb.java:15)

on this line............. public static void main(String[] args) {

Well, I'm sorry but you cannot do that (comment out that }) as then your main method is not ended, or you then are (as noted above) are defining a method within a method.

Go through your code carefully and balance your braces "{ }", properly, then try to compile again. If it still does not compile, then post your modified code here again, with the new, complete, error message, and we can continue.

thanks everyone

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.