what does it mean when an error comes up like this 'class' or 'interface' expected?
6 1573
Where are you getting this error message, in MySQL query? Please describe in detail.
Where are you getting this error message, in MySQL query? Please describe in detail.
this is my code: - 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.jdbc.Driver");
-
} catch (ClassNotFoundException e) {
-
System.out.println ("Could not load the driver");
-
}
-
-
String user, pass, host;
-
user = readEntry("userid: ");
-
pass = readEntry("password: ");
-
host = readEntry("hostname or ip address: ");
-
// userid, password and hostname are obtained from the console
-
-
Connection conn = DriverManager.getConnection
-
("jdbc:mysql://"+host+":3306/test", user, pass);
-
-
/* JDBC default is to commit each SQL statement as it is sent to the database. Setting autocommmit=false changes the default
-
behaviour so that transactions have to be committed explicity.
-
*/
-
conn.setAutoCommit(false);
-
-
// Creating a statement lets us issue commands against the connection.
-
-
Statement s = conn.createStatement();
-
-
// 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.println("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.println("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.println("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.println("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.println("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.println("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.println("Created table Supplier_Order");
-
-
/*
-
*
-
* Piyush Ojha 17 October 2007
-
*
-
* A program to illustrate JDBC PreparedStatement class
-
*
-
*/
-
-
-
-
class min_filmdb_preparedstatement_mysql {
-
public static void main (String args [])
-
throws SQLException, IOException {
-
-
// the following statement loads the MySQL jdbc driver
-
-
try {
-
Class.forName ("com.mysql.jdbc.Driver");
-
} catch (ClassNotFoundException e) {
-
System.out.println ("Could not load the driver");
-
}
-
-
String user, pass, host, database;
-
user = readEntry("userid : ");
-
pass = readEntry("password: ");
-
host = readEntry("hostname or ip address: ");
-
database = readEntry("database: ");
-
// userid, password and hostname are obtained from the console
-
-
Connection conn = DriverManager.getConnection
-
("jdbc:mysql://"+host+":3306/"+database, user, pass);
-
-
/* JDBC default is to commit each SQL statement as it is sent to the database. Setting autocommmit=false changes the default
-
behaviour so that transactions have to be committed explicity.
-
*/
-
conn.setAutoCommit(false);
-
-
// Creating a statement lets us issue commands against the connection.
-
-
Statement s = conn.createStatement();
-
-
// 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.println("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.println("Inserted one row in Actor table using Statement class");
-
-
-
/* INSERTING DATA USING PreparedStatement OBJECT
-
*
-
* The following code is no better than using a Statement object because the PreparedStatement
-
* object is being compiled twice.
-
*
-
*/
-
-
String psq = "INSERT INTO Actor VALUES('Hugh Grant', 'Male', 'British', Date'1966-12-04','Four Weddings')";
-
PreparedStatement ps = conn.prepareStatement(psq); // create PreparedStatement object
-
ps.execute(); // execute the prepared statement
-
-
-
psq = "INSERT INTO Actor VALUES('Helen Mirren', 'Female', 'British', Date'1945-07-26','The Queen')";
-
ps = conn.prepareStatement(psq); // create PreparedStatement object
-
ps.execute(); // execute the prepared statement
-
-
conn.commit();
-
-
System.out.println("Inserted two rows in Actor table using PreparedStatement class");
-
-
/* A PreparedStatement 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(?, ?, ?, ?, ?)";
-
PreparedStatement ps2 = conn.prepareStatement(psq2);
-
-
/* Parameter values are set by various setXXX methods of the
-
PreparedStatement 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,when); // 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.clearParameters();
-
-
// 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.println("Inserting data from text file");
-
-
String data_file = "data_files/actor_data.txt";
-
-
File inputFile = new File(data_file);
-
FileReader inf = new FileReader(inputFile);
-
BufferedReader inb = new BufferedReader(inf);
-
-
System.out.println("Ready to read line");
-
-
line = inb.readLine(); // read a line
-
// System.out.println(line);
-
-
while ( (line != null) ) {
-
tokens = line.split(","); // split line into tokens separated by a comma
-
-
System.out.println(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(tokens[3]); //convert string in yyyy-mm-dd format to date
-
ps2.setDate(4,when); // fourth ? in ps is Date
-
ps2.setString(5, tokens[4]); // fifth ? in ps is a String
-
ps2.execute(); // execute the prepared statement
-
ps2.clearParameters();
-
-
line=inb.readLine(); //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.println("Inserted some actors using PreparedStatement");
-
-
-
-
ResultSet result=s.executeQuery("Select * From Actor");
-
System.out.println("Results: ");
-
while(result.next()) {
-
System.out.println(result.getString(1) +" "+ result.getString(2) + " "+result.getString(3) +" "+ result.getString(4)+" "+ result.getString(5) );
-
}
-
-
-
// We end the transaction and the connection.
-
-
conn.commit();
-
-
-
conn.close();
-
}
-
-
//readEntry function -- to read input string
-
-
static String readEntry(String prompt);
-
try {
-
StringBuffer buffer = new StringBuffer();
-
System.out.print(prompt);
-
System.out.flush();
-
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.println("Inserted some actors");
-
-
-
-
ResultSet result=s.executeQuery("Select * From Actor");
-
System.out.println("Results: ");
-
while(result.next()) {
-
System.out.println(result.getString(1) +" "+ result.getString(2) + " "+result.getString(3) +" "+ result.getString(4)+" "+ result.getString(5) );
-
}
-
-
-
// We end the transaction and the connection.
-
-
conn.commit();
-
-
-
conn.close();
-
}
-
-
//readEntry function -- to read input string
-
static String readEntry(String prompt) {
-
try {
-
StringBuffer buffer = new StringBuffer();
-
System.out.print(prompt);
-
System.out.flush();
-
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 "";
-
}
-
}
-
}
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
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.
Now that you've posted the code, it is a Java syntax problem.
Your line 245 or round about there has -
-
static String readEntry(String prompt);
If you intended this to be the start of a method declaration then it should have been like - static String readEntry(String prompt) {
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
remove the terminating colon on line 245 and put an opening curly brace and see what happens . This works out.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
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.
...
|
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
{
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |