Results 1 to 3 of 3
Thread: Problem executing SELECT query
- 04-25-2011, 04:45 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 24
- Rep Power
- 0
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'
- 04-25-2011, 06:07 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
You need to quote text values in your query
SQL WHERE Clause
- 04-26-2011, 05:30 AM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
SELECT FROM WHERE query
By herfnai in forum JDBCReplies: 3Last Post: 11-24-2008, 11:04 AM -
problem in select query
By herfnai in forum JDBCReplies: 0Last Post: 08-17-2008, 11:47 AM -
Can i use the same statement and resultset objects for executing multiple query?
By RadhaJayalakshmi in forum JDBCReplies: 2Last Post: 07-18-2008, 01:13 PM -
Error When Executing Query
By radz in forum New To JavaReplies: 5Last Post: 06-26-2008, 03:37 AM -
Using a variable in a SELECT FROM WHERE query
By cplmckenzie in forum JDBCReplies: 12Last Post: 04-23-2008, 03:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks