Problem executing SELECT query
Hello. Create the following database with phpmyadmin
CREATE TABLE course
(
c_id VARCHAR(8) NOT NULL PRIMARY KEY,
c_name VARCHAR(40) NOT NULL,
c_ects SMALLINT NOT NULL
) ;
insert into course values ('c1', 'Programming 1', 2) ;
insert into course values ('c2', 'Programming 2', 2) ;
insert into course values ('c3', 'Databases 1', 3) ;
insert into course values ('c4', 'System analysis', 3) ;
insert into course values ('c5', 'Local Area Networks', 3) ;
I made the following method to retrieve the rows by c_id
public static void displayCourse() throws SQLException
{
Statement stmt ;
ResultSet rs ;
stmt = dbConnection.createStatement () ;
rs = stmt.executeQuery ("SELECT c_id, c_name, c_ects FROM course WHERE c_id= "+"c1") ;
while (rs.next ())
System.out.println (rs.getString ("c_id") + " " +
rs.getString ("c_name") + ", ects=" +
rs.getInt ("c_ects")) ;
rs.close () ;
stmt.close () ;
}
When i run the method i get the following message
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Unknown column 'c1' in 'where clause'