Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java.sql.SQLException: Column not found: Unknown column

Status
Not open for further replies.

bishatapar

Programmer
Aug 21, 2003
1
IN
Here is my JAVA programme
------------------------------------------------------------
import java.sql.*;
import java.io.*;
import java.text.*;

public class CreateMovieTables {

static String driver = "com.mysql.jdbc.Driver";
static String protocol = "jdbc:mysql:///test";

String title, leadActor, leadActress, type, dateOfRelease;

Connection connection;
Statement statement;


public void initialize() throws SQLException, ClassNotFoundException {

Class.forName(driver);
connection = DriverManager.getConnection(protocol);

}


public void createTable() throws SQLException {

statement = connection.createStatement();
statement.executeUpdate("CREATE TABLE CATALOGUE(TITLE VARCHAR(100),LEAD_ACTOR VARCHAR(100),LEAD_ACTRESS VARCHAR(100),TYPE VARCHAR(50),RELEASE_DATE DATE)");

}


public void insertData() throws SQLException, IOException {

BufferedReader br = new BufferedReader(new FileReader("catalogue.txt"));

try {

while (true) {

title = br.readLine();

System.out.println("1st line read->"+ title.toString());

if (title == null) {

break;
}

leadActor = br.readLine();
System.out.println("2nd line read->"+ leadActor.toString());
leadActress = br.readLine();
System.out.println("3rd line read->"+ leadActress.toString());
type = br.readLine();
System.out.println("4th line read->"+ type.toString());
dateOfRelease = br.readLine();
System.out.println("5th line read->"+ dateOfRelease.toString());


String sqlString = "INSERT INTO CATALOGUE VALUES(title,leadActor,leadActress,type,dateOfRelease)";

int i= statement.executeUpdate(sqlString);

System.out.println("DATA INSERTED SUCCESSFULY->"+ i);


br.readLine();
// Read the termination line
}

}

catch (EOFException e) {}

finally {

statement.close();
br.close();
}
}

public void close() throws SQLException {
try {
connection.close();
}
catch (SQLException e) {
throw e;
}
}


public static void main(String arg[]) {

CreateMovieTables movies = new CreateMovieTables();

try {

movies.initialize();

System.out.println("Method initialize() returns->");

movies.createTable();

System.out.println("Method createTable() returns->");

movies.insertData();

System.out.println("Method insetData returns->");

movies.close();

}

catch (SQLException sqlException) {

while (sqlException != null) {
sqlException.printStackTrace();
sqlException = sqlException.getNextException();
}

}

catch (IOException ioException) {

System.err.println(ioException.toString());

}

catch (Exception e) {

System.err.println(e.toString());
e.printStackTrace();
}

}
}
------------------------------------------------------------
Here is my programme output

E:\PJSP\C03>java CreateMovieTables
Method initialize() returns->
Method createTable() returns->
1st line read->Lion King
2nd line read->King Lion
3rd line read->Queen Lioness
4th line read->Fiction
5th line read->2000-08-09
java.sql.SQLException: Column not found: Unknown column 'leadActor' in 'field li
st'
at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
at com.mysql.jdbc.MysqlIO.sqlQuery(Unknown Source)
at com.mysql.jdbc.Connection.execSQL(Unknown Source)
at com.mysql.jdbc.Connection.execSQL(Unknown Source)
at com.mysql.jdbc.Statement.executeUpdate(Unknown Source)
at com.mysql.jdbc.jdbc2.Statement.executeUpdate(Unknown Source)
at CreateMovieTables.insertData(CreateMovieTables.java:61)
at CreateMovieTables.main(CreateMovieTables.java:176)
------------------------------------------------------------
Here is my MYSQL output
------------------------------------------------------------
mysql> show columns from catalogue;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| TITLE | varchar(100) | YES | | NULL | |
| LEAD_ACTOR | varchar(100) | YES | | NULL | |
| LEAD_ACTRESS | varchar(100) | YES | | NULL | |
| TYPE | varchar(50) | YES | | NULL | |
| RELEASE_DATE | date | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
5 rows in set (0.02 sec)

mysql>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top