4
String  sql = "SELECT (Employee_name, Password) FROM employee WHERE (Employee_name = '"+name+"'  AND Password = '"+password+"')";

and getting the following exception in JSP java.sql.sqlexception insert operand should contain 1 column(s)

Please help.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
user3507176
  • 41
  • 1
  • 1
  • 3

3 Answers3

5

Correct way is

String  sql = "SELECT Employee_name, Password FROM employee WHERE Employee_name = '"+name+"'  AND Password = '"+password+"'";

You can keep () for where clause but not in select list. This is what happens in your case

mysql> select (firstname,email) from users limit 1 ;
ERROR 1241 (21000): Operand should contain 1 column(s)
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
2

Remove brackets and it will work.

String  sql = "SELECT Employee_name, Password 
           FROM employee WHERE Employee_name = '"+name+"'  
                      AND Password = '"+password+"'";

Generally we are using brackets when we need to add Nested Queries and for combining conditions. if you add brackets for column names Mysql identified it as a single column. Thats why the error comes out as its is.

Lasitha Benaragama
  • 2,201
  • 2
  • 27
  • 43
1

Your query must be this:

String  sql = "SELECT Employee_name, Password 
                  FROM employee 
                   WHERE (Employee_name = '"+name+"'  
                     AND Password = '"+password+"')";
Code Lღver
  • 15,573
  • 16
  • 56
  • 75