aspose file tools*
The moose likes JDBC and the fly likes Compilation Fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Compilation Fails" Watch "Compilation Fails" New topic
Author

Compilation Fails

karthikeyan piramanayagam
Greenhorn

Joined: Feb 16, 2006
Posts: 22
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

Joined: Nov 19, 2003
Posts: 7
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

Joined: Feb 16, 2006
Posts: 22
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Mar 06, 2001
Posts: 13459

Moving to the JDBC forum.

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compilation Fails
 
Similar Threads
Is it possible to view the SQL that got executed?
what is the dao layer
copy data between two different servers
Help with java.io.FileNotFoundException
passing array parameter in URL