473,395 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

errors

what does it mean when an error comes up like this 'class' or 'interface' expected?
Nov 9 '07 #1
6 1573
mwasif
802 Expert 512MB
Where are you getting this error message, in MySQL query? Please describe in detail.
Nov 9 '07 #2
Where are you getting this error message, in MySQL query? Please describe in detail.
this is my code:

Expand|Select|Wrap|Line Numbers
  1.  import java.sql.*; 
  2. import java.io.*; 
  3.  
  4. class min_filmdb_rel_mysql { 
  5.   public static void main (String args []) 
  6.       throws SQLException, IOException { 
  7.  
  8.       // the following statement loads the MySQL jdbc driver
  9.  
  10.     try {
  11.       Class.forName ("com.mysql.jdbc.Driver");
  12.     } catch (ClassNotFoundException e) {
  13.         System.out.println ("Could not load the driver"); 
  14.       }
  15.  
  16.     String user, pass, host;
  17.     user = readEntry("userid: ");
  18.     pass = readEntry("password: ");
  19.     host = readEntry("hostname or ip address: ");
  20.     //  userid, password and hostname are obtained from the console
  21.  
  22.     Connection conn = DriverManager.getConnection
  23.                   ("jdbc:mysql://"+host+":3306/test", user, pass);
  24.  
  25.     /* JDBC default is to commit each SQL statement as it is sent to the database.  Setting autocommmit=false changes the default
  26.        behaviour so that transactions have to be committed explicity.
  27.      */
  28.     conn.setAutoCommit(false);
  29.  
  30.     // Creating a statement lets us issue commands against the connection.
  31.  
  32.     Statement s = conn.createStatement();
  33.  
  34.      // Creating and populating Customer table
  35.  
  36.      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))");
  37.      System.out.println("Created table Customer");
  38.  
  39.      // Creating and populating Supplier table
  40.  
  41.      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))");
  42.      System.out.println("Created table Supplier");
  43.  
  44.      // Creating and populating Product table
  45.  
  46.      s.executeUpdate("create table IF NOT EXISTS Product( ProductID VARCHAR(20)  PRIMARY KEY,  SupplierID VARCHAR(20) PRIMARY KEY,  ProductName VARCHAR(20), Price VARCHAR(20))");
  47.      System.out.println("Created table Product");
  48.  
  49.      // Creating and populating Staff table
  50.  
  51.      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))");
  52.      System.out.println("Created table Staff");
  53.  
  54.      // Creating and populating Department table
  55.  
  56.      s.executeUpdate("create table IF NOT EXISTS Department( DeptID VARCHAR(20)  PRIMARY KEY,  DeptName VARCHAR(20))");
  57.      System.out.println("Created table Department");
  58.  
  59.      // Creating and populating Customer_Order table
  60.  
  61.      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))");
  62.      System.out.println("Created table Cutomer_Order");
  63.  
  64.      // Creating and populating Supplier_Order table
  65.  
  66.      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))");
  67.      System.out.println("Created table Supplier_Order");
  68.  
  69.      /*
  70.  *
  71.  *  Piyush Ojha 17 October 2007
  72.  *
  73.  *  A program to illustrate JDBC PreparedStatement class
  74.  *
  75.  */
  76.  
  77.  
  78.  
  79. class min_filmdb_preparedstatement_mysql { 
  80.     public static void main (String args []) 
  81.     throws SQLException, IOException { 
  82.  
  83.     // the following statement loads the MySQL jdbc driver
  84.  
  85.     try {
  86.         Class.forName ("com.mysql.jdbc.Driver");
  87.     } catch (ClassNotFoundException e) {
  88.         System.out.println ("Could not load the driver"); 
  89.     }
  90.  
  91.     String user, pass, host, database;
  92.     user = readEntry("userid  : ");
  93.     pass = readEntry("password: ");
  94.     host = readEntry("hostname or ip address: ");
  95.     database = readEntry("database: ");
  96.     //  userid, password and hostname are obtained from the console
  97.  
  98.     Connection conn = DriverManager.getConnection
  99.         ("jdbc:mysql://"+host+":3306/"+database, user, pass);
  100.  
  101.     /* JDBC default is to commit each SQL statement as it is sent to the database.  Setting autocommmit=false changes the default
  102.        behaviour so that transactions have to be committed explicity.
  103.     */
  104.     conn.setAutoCommit(false);
  105.  
  106.     // Creating a statement lets us issue commands against the connection.
  107.  
  108.     Statement s = conn.createStatement();
  109.  
  110.     // Creating and populating Actor table
  111.  
  112.     s.executeUpdate("CREATE TABLE IF NOT EXISTS Actor( ActorName VARCHAR(20)  PRIMARY KEY,  Sex VARCHAR(6), Nationality VARCHAR(20), DOB DATE,  DebutFilmTitle VARCHAR(30))");
  113.     System.out.println("Created table Actor");
  114.  
  115.     s.executeUpdate("DELETE FROM Actor WHERE TRUE"); // delete all rows from Actor table
  116.  
  117.     // INSERTING DATA USING Statement OBJECT
  118.  
  119.     s.executeUpdate("INSERT INTO  Actor VALUES('George Clooney', 'Male', 'American', Date'1965-12-04','Casualty')");
  120.     conn.commit();
  121.  
  122.     System.out.println("Inserted one row in Actor table using Statement class");
  123.  
  124.  
  125.     /* INSERTING DATA USING PreparedStatement OBJECT
  126.      *
  127.      * The following code is no better than using a Statement object because the PreparedStatement
  128.      * object is being compiled twice.
  129.      * 
  130.      */
  131.  
  132.     String psq = "INSERT INTO  Actor VALUES('Hugh Grant', 'Male', 'British', Date'1966-12-04','Four Weddings')";
  133.     PreparedStatement ps = conn.prepareStatement(psq); // create PreparedStatement object
  134.     ps.execute(); // execute the prepared statement
  135.  
  136.  
  137.     psq = "INSERT INTO  Actor VALUES('Helen Mirren', 'Female', 'British', Date'1945-07-26','The Queen')";
  138.     ps = conn.prepareStatement(psq); // create PreparedStatement object
  139.     ps.execute(); // execute the prepared statement
  140.  
  141.     conn.commit();
  142.  
  143.     System.out.println("Inserted two rows in Actor table using PreparedStatement class");
  144.  
  145.     /* A PreparedStatement is more useful when it is compiled  with a number
  146.        of parameters whose value is assigned before the prepared statement is
  147.        executed.  In the following declaration, each ? stands for a parameter.
  148.     */
  149.  
  150.     String psq2 = "insert into Actor values(?, ?, ?, ?, ?)";
  151.     PreparedStatement ps2 = conn.prepareStatement(psq2);
  152.  
  153.     /* Parameter values are set by various setXXX methods of the
  154.        PreparedStatement class.
  155.  
  156.        Note how a string is converted to a Java Date before it is used 
  157.        in the setDate method. (Is there a simpler way?))
  158.     */
  159.  
  160.     ps2.setString(1, "Clark Gable"); // first ? in ps is a String
  161.     ps2.setString(2, "Male"); // second ? in ps is a String
  162.     ps2.setString(3, "American"); // third ? in ps is a String     
  163.  
  164.     // Next line emphasises that it is java.sql.Date and NOT java.util.Date
  165.     java.sql.Date when = new java.sql.Date(0); // No default constructor without an argument
  166.     when = new java.sql.Date(0).valueOf("1911-06-23"); //convert string in yyyy-mm-dd format to date 
  167.  
  168.     ps2.setDate(4,when); // fourth ? in ps is Date
  169.     ps2.setString(5, "Gone with the Wind"); // fifth ? in ps is a String
  170.  
  171.     // Now execute the prepared statement to load data
  172.  
  173.     ps2.execute(); // execute the prepared statement
  174.  
  175.     // Clear the parameter values so that they can be set again.
  176.     ps2.clearParameters();
  177.  
  178.     // ESSENTIAL JAVA CODE FOR LOADING DATA FROM A TEXT FILE
  179.  
  180.     // We will reuse ps2 which has been compiled previously.
  181.  
  182.     String line; // Data from text file to be read one line at a time
  183.  
  184.     String[] tokens; // line will be parsed into an array of Strings
  185.  
  186.     System.out.println("Inserting data from text file");
  187.  
  188.     String data_file = "data_files/actor_data.txt";
  189.  
  190.     File inputFile = new File(data_file);
  191.     FileReader inf = new FileReader(inputFile);
  192.     BufferedReader inb = new BufferedReader(inf);
  193.  
  194.     System.out.println("Ready to read line");
  195.  
  196.     line = inb.readLine(); // read a line
  197.     // System.out.println(line);
  198.  
  199.     while ( (line != null) ) {
  200.         tokens = line.split(","); // split line into tokens separated by a comma
  201.  
  202.         System.out.println(tokens[0]+" "+tokens[1]+" "+tokens[2]+" "+tokens[3]+" "+tokens[04]+" ");
  203.  
  204.         // At this point one should really trim leading and trailing space characters from the tokens. 
  205.  
  206.         ps2.setString(1, tokens[0]); // first ? in ps is a String
  207.         ps2.setString(2, tokens[1]); // second ? in ps is a String
  208.         ps2.setString(3, tokens[2]); // third ? in ps is a String     
  209.         when = new java.sql.Date(0).valueOf(tokens[3]); //convert string in yyyy-mm-dd format to date 
  210.         ps2.setDate(4,when); // fourth ? in ps is Date
  211.         ps2.setString(5, tokens[4]); // fifth ? in ps is a String
  212.         ps2.execute(); // execute the prepared statement
  213.         ps2.clearParameters();
  214.  
  215.         line=inb.readLine(); //read next line
  216.  
  217.     }
  218.  
  219.     conn.commit(); // commit after all data has been inserted
  220.     inb.close(); // close the buffered reader
  221.     inf.close(); // close the file
  222.  
  223.  
  224.     System.out.println("Inserted some actors using PreparedStatement");
  225.  
  226.  
  227.  
  228.     ResultSet result=s.executeQuery("Select * From Actor");
  229.     System.out.println("Results: ");
  230.     while(result.next()) {
  231.         System.out.println(result.getString(1) +"  "+ result.getString(2) + "  "+result.getString(3) +"  "+  result.getString(4)+"  "+ result.getString(5) );
  232.     }
  233.  
  234.  
  235.     // We end the transaction and the connection.
  236.  
  237.     conn.commit();
  238.  
  239.  
  240.     conn.close();
  241.     } 
  242.  
  243.     //readEntry function -- to read input string
  244.  
  245.     static String readEntry(String prompt);
  246.     try {
  247.         StringBuffer buffer = new StringBuffer();
  248.         System.out.print(prompt);
  249.         System.out.flush();
  250.         int c = System.in.read();
  251.         while(c != '\n' && c != -1) {
  252.         buffer.append((char)c);
  253.         c = System.in.read();
  254.         }
  255.         return buffer.toString().trim();
  256.     } catch (IOException e) {
  257.         return "";
  258.     }
  259.     } 
  260.  
  261.  
  262.      //s.executeUpdate("insert into Actor values('George Clooney', 'Male', 'American', Date'1965-12-04','Casualty')");
  263.  
  264.      conn.commit();
  265.      System.out.println("Inserted some actors");
  266.  
  267.  
  268.  
  269.      ResultSet result=s.executeQuery("Select * From Actor");
  270.      System.out.println("Results: ");
  271.      while(result.next()) {
  272.      System.out.println(result.getString(1) +"  "+ result.getString(2) + "  "+result.getString(3) +"  "+  result.getString(4)+"  "+ result.getString(5) );
  273.      }
  274.  
  275.  
  276.      // We end the transaction and the connection.
  277.  
  278.      conn.commit();
  279.  
  280.  
  281.      conn.close();
  282.   } 
  283.  
  284.   //readEntry function -- to read input string
  285.   static String readEntry(String prompt) {
  286.      try {
  287.        StringBuffer buffer = new StringBuffer();
  288.        System.out.print(prompt);
  289.        System.out.flush();
  290.        int c = System.in.read();
  291.        while(c != '\n' && c != -1) {
  292.          buffer.append((char)c);
  293.          c = System.in.read();
  294.        }
  295.        return buffer.toString().trim();
  296.      } catch (IOException e) {
  297.        return "";
  298.        }
  299.    }
  300. }
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
Nov 9 '07 #3
r035198x
13,262 8TB
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.
Nov 9 '07 #4
r035198x
13,262 8TB
Now that you've posted the code, it is a Java syntax problem.

Your line 245 or round about there has
Expand|Select|Wrap|Line Numbers
  1.  
  2.     static String readEntry(String prompt);
If you intended this to be the start of a method declaration then it should have been like

Expand|Select|Wrap|Line Numbers
  1.      static String readEntry(String prompt) {
Nov 9 '07 #5
JosAH
11,448 Expert 8TB
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
Nov 9 '07 #6
heat84
118 100+
remove the terminating colon on line 245 and put an opening curly brace and see what happens . This works out.
Nov 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: mikey_boy | last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP script with makes a simple connection to a mysql database called firstdb and just pulls back the results and displays on the...
2
by: Trev | last post by:
SQL Server 2000 BE, Access 2002 FE. I want to write a stored procedure, that will among other things log errors to a table, I want to be able to report a summary of work done and errors to the...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
0
by: doli | last post by:
Hi, I have the following piece of code which iterates through the potential errors: i =0 For Each error_item in myConn.Errors DTSPackageLog.WriteStringToLog myConn.Errors(i).Description...
4
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when all the textboxes are valid. I found a solution,...
2
by: Samuel R. Neff | last post by:
Within the past few weeks we've been getting a lot of compiler errors in two classes when no errors actually exist. The error always reports as Name '_stepResizeRelocator' is not declared. ...
24
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
0
by: clemrock | last post by:
Help w/ errors.add_to_base between controller and model Hello, I'm having trouble in routing some errors between model and controller. The errors produced in the controller...
2
by: =?Utf-8?B?UmFuZHlz?= | last post by:
This just started when I updated to sp 1 working on a APS.net, Visual Studio 2008, c# Project. When I open a project, I get tons of Errors showing in the list 300+ if I double click on them I go...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.