0

Hi
I am trying to extract some information from data base
and i am writting this query

java.sql.Statement s = dbCon.createStatement();
ResultSet r = null;
r = s.executeQuery("select * from emp where description="+courseName);

If the course have value
description="Fundamental of Science"
then it says "syntax error at or near of"

and if description="SAD"
then it said error "column "sad" does not exist
means its converting to lower case

where, i am accepting the string value for description from a JSP page,
i am returning the value in the bean by using get set method
and i am writing the query in bean

i have checked that its returning the value properly for the parameter "description"
Please help

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Ezzaral
1

You need single quotes around the string value in your where clause, so that would be description='"+courseName+"'" A better way would be to use a PreparedStatement, which can re-used if you need to look up other course names

java.sql.PreparedStatement prepStmt = dbCon.prepareStatement("select * from emp where description=?");
prepStmt.setString(1, courseName);
ResultSet r = prepStmt.executeQuery();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.