LIke operator in JDBC
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   SaiPrabhu12_PrabhuSai21
Posted On:   Wednesday, May 19, 2004 06:14 AM

Problem in JDBC , when using LIKE operator. LINE 1 : String temp = "AA"; LINE 2 : String query = "select * from emp where EMPNAME like '*temp*' "; LINE 3 : Staement st = con.createStaement(); LINE 4 : ResultSet rs = st.executeQuery(query); '*' character is not getting evaluated. In MS ACCESS2000 only * is accepted instead of '%'. Moreover in MS ACCESS the like operator has to be used within double quotes as a String. whereas in other databases, it accepts single quotes as a String. Ex: In MS ACCESS select * from emp where ename like "*aa*"; Other Databases select * from emp where ename like '%aa%';    More>>

Problem in JDBC , when using LIKE operator.

LINE 1 : String temp = "AA";

LINE 2 : String query = "select * from emp where EMPNAME like '*temp*' ";

LINE 3 : Staement st = con.createStaement();

LINE 4 : ResultSet rs = st.executeQuery(query);

'*' character is not getting evaluated. In MS ACCESS2000 only * is accepted instead of '%'. Moreover in MS ACCESS the like operator has to be used within double quotes as a String. whereas in other databases, it accepts single quotes as a String.


Ex:

In MS ACCESS

select * from emp where ename like "*aa*";

Other Databases

select * from emp where ename like '%aa%';

In my situation iam passing a Variable inside a like operator and '*' is used.

For the above Scenario, Please help me out.

If possible Kindly let me know the exact Syntax.

Please give me the answer as LINE1,LINE2,LINE3,LINE4,

I have verified in JDBC Spec also, it has been specified to use escape sequence.that too did not work.

Due to this, My project is in hold for about 4 days. I could not find a suitable solution.

Please help me out.

   <<Less

Re: LIke operator in JDBC

Posted By:   David_Thornton  
Posted On:   Wednesday, May 19, 2004 05:15 PM



LINE 1 : String temp = "AA";
LINE 2 : String query = "select * from emp where EMPNAME like '%" + temp + "%'";
LINE 3 : Staement st = con.createStaement();
LINE 4 : ResultSet rs = st.executeQuery(query);
About | Sitemap | Contact