errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paulq182
    New Member
    • Nov 2007
    • 4

    #1

    errors

    what does it mean when an error comes up like this 'class' or 'interface' expected?
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Where are you getting this error message, in MySQL query? Please describe in detail.

    Comment

    • paulq182
      New Member
      • Nov 2007
      • 4

      #3
      Originally posted by mwasif
      Where are you getting this error message, in MySQL query? Please describe in detail.
      this is my code:

      [CODE=java] import java.sql.*;
      import java.io.*;

      class min_filmdb_rel_ mysql {
      public static void main (String args [])
      throws SQLException, IOException {

      // the following statement loads the MySQL jdbc driver

      try {
      Class.forName ("com.mysql.jdb c.Driver");
      } catch (ClassNotFoundE xception e) {
      System.out.prin tln ("Could not load the driver");
      }

      String user, pass, host;
      user = readEntry("user id: ");
      pass = readEntry("pass word: ");
      host = readEntry("host name or ip address: ");
      // userid, password and hostname are obtained from the console

      Connection conn = DriverManager.g etConnection
      ("jdbc:mysql ://"+host+":33 06/test", user, pass);

      /* JDBC default is to commit each SQL statement as it is sent to the database. Setting autocommmit=fal se changes the default
      behaviour so that transactions have to be committed explicity.
      */
      conn.setAutoCom mit(false);

      // Creating a statement lets us issue commands against the connection.

      Statement s = conn.createStat ement();

      // Creating and populating Customer table

      s.executeUpdate ("create table IF NOT EXISTS Customer( CustomerID VARCHAR(20) PRIMARY KEY, FirstName VARCHAR(20), Surname VARCHAR(20), Address VARCHAR(30), Post code VARCHAR(7), Telephone No VARCHAR(15), Email VARCHAR(20))");
      System.out.prin tln("Created table Customer");

      // Creating and populating Supplier table

      s.executeUpdate ("create table IF NOT EXISTS Supplier( SupplierID VARCHAR(20) PRIMARY KEY, SupplierName VARCHAR(20), Address VARCHAR(20), Post code VARCHAR(7), Telephone No VARCHAR(15), Email VARCHAR(20))");
      System.out.prin tln("Created table Supplier");

      // Creating and populating Product table

      s.executeUpdate ("create table IF NOT EXISTS Product( ProductID VARCHAR(20) PRIMARY KEY, SupplierID VARCHAR(20) PRIMARY KEY, ProductName VARCHAR(20), Price VARCHAR(20))");
      System.out.prin tln("Created table Product");

      // Creating and populating Staff table

      s.executeUpdate ("create table IF NOT EXISTS Staff( StaffID VARCHAR(20) PRIMARY KEY, DeptID VARCHAR(20) PRIMARY KEY, FirstName VARCHAR(20), Surname VARCHAR(20), Address VARCHAR(20), Post code VARCHAR(7), Telephone No VARCHAR(15), Mobile No VARCHAR(11))");
      System.out.prin tln("Created table Staff");

      // Creating and populating Department table

      s.executeUpdate ("create table IF NOT EXISTS Department( DeptID VARCHAR(20) PRIMARY KEY, DeptName VARCHAR(20))");
      System.out.prin tln("Created table Department");

      // Creating and populating Customer_Order table

      s.executeUpdate ("create table IF NOT EXISTS Customer_Order( CustomerID VARCHAR(20) PRIMARY KEY, OrderID VARCHAR(20) PRIMARY KEY, ProductID VARCHAR(20) PRIMARY KEY, ProductName VARCHAR(20), Qty VARCHAR(10), Price VARCHAR(10), Paid VARCHAR(10))");
      System.out.prin tln("Created table Cutomer_Order") ;

      // Creating and populating Supplier_Order table

      s.executeUpdate ("create table IF NOT EXISTS Supplier_Order( SupplierID VARCHAR(20) PRIMARY KEY, OrderID VARCHAR(20) PRIMARY KEY, ProductID VARCHAR(20) PRIMARY KEY, ProductName VARCHAR(20), Qty VARCHAR(10), Price VARCHAR(10))");
      System.out.prin tln("Created table Supplier_Order" );

      /*
      *
      * Piyush Ojha 17 October 2007
      *
      * A program to illustrate JDBC PreparedStateme nt class
      *
      */



      class min_filmdb_prep aredstatement_m ysql {
      public static void main (String args [])
      throws SQLException, IOException {

      // the following statement loads the MySQL jdbc driver

      try {
      Class.forName ("com.mysql.jdb c.Driver");
      } catch (ClassNotFoundE xception e) {
      System.out.prin tln ("Could not load the driver");
      }

      String user, pass, host, database;
      user = readEntry("user id : ");
      pass = readEntry("pass word: ");
      host = readEntry("host name or ip address: ");
      database = readEntry("data base: ");
      // userid, password and hostname are obtained from the console

      Connection conn = DriverManager.g etConnection
      ("jdbc:mysql ://"+host+":33 06/"+database, user, pass);

      /* JDBC default is to commit each SQL statement as it is sent to the database. Setting autocommmit=fal se changes the default
      behaviour so that transactions have to be committed explicity.
      */
      conn.setAutoCom mit(false);

      // Creating a statement lets us issue commands against the connection.

      Statement s = conn.createStat ement();

      // Creating and populating Actor table

      s.executeUpdate ("CREATE TABLE IF NOT EXISTS Actor( ActorName VARCHAR(20) PRIMARY KEY, Sex VARCHAR(6), Nationality VARCHAR(20), DOB DATE, DebutFilmTitle VARCHAR(30))");
      System.out.prin tln("Created table Actor");

      s.executeUpdate ("DELETE FROM Actor WHERE TRUE"); // delete all rows from Actor table

      // INSERTING DATA USING Statement OBJECT

      s.executeUpdate ("INSERT INTO Actor VALUES('George Clooney', 'Male', 'American', Date'1965-12-04','Casualty') ");
      conn.commit();

      System.out.prin tln("Inserted one row in Actor table using Statement class");


      /* INSERTING DATA USING PreparedStateme nt OBJECT
      *
      * The following code is no better than using a Statement object because the PreparedStateme nt
      * object is being compiled twice.
      *
      */

      String psq = "INSERT INTO Actor VALUES('Hugh Grant', 'Male', 'British', Date'1966-12-04','Four Weddings')";
      PreparedStateme nt ps = conn.prepareSta tement(psq); // create PreparedStateme nt object
      ps.execute(); // execute the prepared statement


      psq = "INSERT INTO Actor VALUES('Helen Mirren', 'Female', 'British', Date'1945-07-26','The Queen')";
      ps = conn.prepareSta tement(psq); // create PreparedStateme nt object
      ps.execute(); // execute the prepared statement

      conn.commit();

      System.out.prin tln("Inserted two rows in Actor table using PreparedStateme nt class");

      /* A PreparedStateme nt is more useful when it is compiled with a number
      of parameters whose value is assigned before the prepared statement is
      executed. In the following declaration, each ? stands for a parameter.
      */

      String psq2 = "insert into Actor values(?, ?, ?, ?, ?)";
      PreparedStateme nt ps2 = conn.prepareSta tement(psq2);

      /* Parameter values are set by various setXXX methods of the
      PreparedStateme nt class.

      Note how a string is converted to a Java Date before it is used
      in the setDate method. (Is there a simpler way?))
      */

      ps2.setString(1 , "Clark Gable"); // first ? in ps is a String
      ps2.setString(2 , "Male"); // second ? in ps is a String
      ps2.setString(3 , "American") ; // third ? in ps is a String

      // Next line emphasises that it is java.sql.Date and NOT java.util.Date
      java.sql.Date when = new java.sql.Date(0 ); // No default constructor without an argument
      when = new java.sql.Date(0 ).valueOf("1911-06-23"); //convert string in yyyy-mm-dd format to date

      ps2.setDate(4,w hen); // fourth ? in ps is Date
      ps2.setString(5 , "Gone with the Wind"); // fifth ? in ps is a String

      // Now execute the prepared statement to load data

      ps2.execute(); // execute the prepared statement

      // Clear the parameter values so that they can be set again.
      ps2.clearParame ters();

      // ESSENTIAL JAVA CODE FOR LOADING DATA FROM A TEXT FILE

      // We will reuse ps2 which has been compiled previously.

      String line; // Data from text file to be read one line at a time

      String[] tokens; // line will be parsed into an array of Strings

      System.out.prin tln("Inserting data from text file");

      String data_file = "data_files/actor_data.txt" ;

      File inputFile = new File(data_file) ;
      FileReader inf = new FileReader(inpu tFile);
      BufferedReader inb = new BufferedReader( inf);

      System.out.prin tln("Ready to read line");

      line = inb.readLine(); // read a line
      // System.out.prin tln(line);

      while ( (line != null) ) {
      tokens = line.split(",") ; // split line into tokens separated by a comma

      System.out.prin tln(tokens[0]+" "+tokens[1]+" "+tokens[2]+" "+tokens[3]+" "+tokens[04]+" ");

      // At this point one should really trim leading and trailing space characters from the tokens.

      ps2.setString(1 , tokens[0]); // first ? in ps is a String
      ps2.setString(2 , tokens[1]); // second ? in ps is a String
      ps2.setString(3 , tokens[2]); // third ? in ps is a String
      when = new java.sql.Date(0 ).valueOf(token s[3]); //convert string in yyyy-mm-dd format to date
      ps2.setDate(4,w hen); // fourth ? in ps is Date
      ps2.setString(5 , tokens[4]); // fifth ? in ps is a String
      ps2.execute(); // execute the prepared statement
      ps2.clearParame ters();

      line=inb.readLi ne(); //read next line

      }

      conn.commit(); // commit after all data has been inserted
      inb.close(); // close the buffered reader
      inf.close(); // close the file


      System.out.prin tln("Inserted some actors using PreparedStateme nt");



      ResultSet result=s.execut eQuery("Select * From Actor");
      System.out.prin tln("Results: ");
      while(result.ne xt()) {
      System.out.prin tln(result.getS tring(1) +" "+ result.getStrin g(2) + " "+result.getStr ing(3) +" "+ result.getStrin g(4)+" "+ result.getStrin g(5) );
      }


      // We end the transaction and the connection.

      conn.commit();


      conn.close();
      }

      //readEntry function -- to read input string

      static String readEntry(Strin g prompt);
      try {
      StringBuffer buffer = new StringBuffer();
      System.out.prin t(prompt);
      System.out.flus h();
      int c = System.in.read( );
      while(c != '\n' && c != -1) {
      buffer.append(( char)c);
      c = System.in.read( );
      }
      return buffer.toString ().trim();
      } catch (IOException e) {
      return "";
      }
      }
      }


      //s.executeUpdate ("insert into Actor values('George Clooney', 'Male', 'American', Date'1965-12-04','Casualty') ");

      conn.commit();
      System.out.prin tln("Inserted some actors");



      ResultSet result=s.execut eQuery("Select * From Actor");
      System.out.prin tln("Results: ");
      while(result.ne xt()) {
      System.out.prin tln(result.getS tring(1) +" "+ result.getStrin g(2) + " "+result.getStr ing(3) +" "+ result.getStrin g(4)+" "+ result.getStrin g(5) );
      }


      // We end the transaction and the connection.

      conn.commit();


      conn.close();
      }

      //readEntry function -- to read input string
      static String readEntry(Strin g prompt) {
      try {
      StringBuffer buffer = new StringBuffer();
      System.out.prin t(prompt);
      System.out.flus h();
      int c = System.in.read( );
      while(c != '\n' && c != -1) {
      buffer.append(( char)c);
      c = System.in.read( );
      }
      return buffer.toString ().trim();
      } catch (IOException e) {
      return "";
      }
      }
      }[/CODE]

      these are my errors:

      illegal start of type line 247
      <identifier> expected line 260
      <identifier> expected line 266
      <identifier> expected line 267
      <identifier> expected line 272
      illegal start of type line 273
      <identifier> expected line 280
      <identifier> expected line 283
      'class' or 'interface' expected line 287
      'class' or 'interface' expected line 302
      'class' or 'interface' expected line 303

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by paulq182
        what does it mean when an error comes up like this 'class' or 'interface' expected?
        Smells like a Java error message to me. Please verify that you are posting in the correct forum.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Now that you've posted the code, it is a Java syntax problem.

          Your line 245 or round about there has [CODE=java]

          static String readEntry(Strin g prompt);[/CODE]

          If you intended this to be the start of a method declaration then it should have been like

          [CODE=java] static String readEntry(Strin g prompt) {[/CODE]

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by paulq182
            these are my errors:

            illegal start of type line 247
            <identifier> expected line 260
            <identifier> expected line 266
            <identifier> expected line 267
            <identifier> expected line 272
            illegal start of type line 273
            <identifier> expected line 280
            <identifier> expected line 283
            'class' or 'interface' expected line 287
            'class' or 'interface' expected line 302
            'class' or 'interface' expected line 303
            Check your curly brackets; they don't all match up. Line 245 is extremely suspicious.

            kind regards,

            Jos

            Comment

            • heat84
              New Member
              • Nov 2007
              • 118

              #7
              remove the terminating colon on line 245 and put an opening curly brace and see what happens . This works out.

              Comment

              Working...