how to useLIKE operator in JSP?

Dear everyone,

i have a task in which i have to use LIKE operator to search the database and retrieve the answer..

but it is giving only in ordered form, how should i use it

i will show you the code

PreparedStatement pr=con.prepareStatement("select eid from lang where language like ? ");

[345 byte] By [senthil_yogaa] at [2007-11-27 4:11:34]
«« random
»» JApplet
# 1
This has actually nothing to do with JSP, but with SQL.Refer to some SQL tutorials how to use the LIKE query: http://www.google.com/search?q=sql+like+tutorial
BalusCa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

i know to use LIKE operator to check a single data like

LIKE '%data%'

i am asking , how to use it , while we are getting "requestparameter as ?"

ie

<%

String s2=request.getParameter("language");

%>

<%

int i=0;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:langskill");

PreparedStatement pr=con.prepareStatement("select eid from lang where language like ? ");

pr.setString(1,s2);

senthil_yogaa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
I don't get you? Or don't you know how to add "%" to the s2?
BalusCa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
thanx for ur king informationis this correctPreparedStatement pr=con.prepareStatement("select eid from lang where language like '%s2%' ");pr.setString(1,s2);
senthil_yogaa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
No, add it to the s2 and not to the PreparedStatement query.
BalusCa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

i really appreciate for your response sir...

but i am not able to get that...

can u please edit the code and send me sir...

<%

String s2=request.getParameter("language");

%>

<%

int i=0;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:langskill");

PreparedStatement pr=con.prepareStatement("select eid from lang where language like ? ");

pr.setString(1,s2);

ResultSet rs=pr.executeQuery();

while (rs.next ())

{

String eid = rs.getString("eid");

out.println(eid);

}

//out.println("no employee are found ");

}

catch(Exception e)

{

System.out.println(e);

}

%>

senthil_yogaa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Append "%" in to the front and end of s2.pr.setString(1, "%" + s2 + "%");
BalusCa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
reply to Mr BaluC,Thank you a lot....i really appreciate your guidance and my hats off to you ......thank u very muchhhhhhhhhhhhhhhhhhhhhhhhhhhhh.......
senthil_yogaa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
it really worked out....and i got all the datas.......thanx
senthil_yogaa at 2007-7-12 9:17:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...