search results not correct

i need to do search where user may enter more than 1 word. for example: hello, world.

i have some codes here but it didnt perform the search correctly. what's my mistake? pls help...

String sDB="db", sUsr= "", sPwd="";

String search = (String)request.getParameter("txtSearch");

String parameter = (String)"%"+search+"%";

String sSQL = "select * from tbl where Title LIKE '"+parameter+"'";

[428 byte] By [kacheeka] at [2007-10-2 18:27:39]
# 1
String search = (String)request.getParameter("txtSearch");now tokenize the string using stringTokenizer and format the query as String sSQL = "select * from tbl where Title LIKE '"+parameter+"'" or title like '%dsfaads%' or title like '%dfds%' etc
Rahul.Guptaa at 2007-7-13 19:48:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Handcrufted SQL statements are not good. They are prone to including delimiter characters like , etc. Use String sSQL = "select * from tbl where Title LIKE '?'";and setString()
BIJ001a at 2007-7-13 19:48:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> Handcrufted SQL statements are not good. They are

> prone to including delimiter characters like ,

> etc.

>

> Use

> > String sSQL = "select * from tbl where Title LIKE

> '?'";

>

> and setString()

how and where should i apply the setString()?

kacheeka at 2007-7-13 19:48:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

i did this in my coding (below)

// ....

String sSQL = "select * from tblArticle where Title LIKE '?'";

//....

try{

Ps = Con.prepareStatement(sSQL);

Ps.setString( "%" + request.getParameter("txtSearch") + "%");

Rs = Ps.executeQuery();

}

but it gives an error. = setString(int,java.lang.String) in java.sql.PreparedStatement cannot be applied to (java.lang.String)Ps.setString( "%" + request.getParameter("txtSearch") + "%");

what's wrong with it?

kacheeka at 2007-7-13 19:48:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...