Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compilation Fails

 
karthikeyan piramanayagam
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

In my Servlet project,im using the following query to fetch those employee names which are LIKE the variable "emp". But while i compile this i'm getting a "Incompatible type" compilation error.

If anyone knows the answer, plz help me out.....

String sql_getAll = "select * from DEPARTMENT WHERE EMPNAME LIKE '" + %emp% + "';";

I'm using this query along with Result Set.


Thnaks in Advance...
P.karthikeyan
 
Kannan Venkateshan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karthikeyan,

why do you need a %emp% in your String statement ???

just use

String sql_getAll = "select * from DEPARTMENT WHERE EMPNAME LIKE '" +emp+ "';";

and i guess things should work fine.

cheers,

Kannan
 
karthikeyan piramanayagam
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u very much, but, since i'm using the LIKE keyword, i should use the % otherwise it will not fetch all the relevant names. So i have use the %. So if u ahve any other ideas plz let me know

regards...
P.karthikeyan
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you put the % inside the String quotes:

String sql_getAll = "select * from DEPARTMENT WHERE EMPNAME LIKE '%" + emp + "%'";
Also, you do not need the semicolon inside the string, it will cause errors.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum.

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic