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

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.