aspose file tools*
The moose likes JDBC and the fly likes How to provide willdcard search Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to provide willdcard search " Watch "How to provide willdcard search " New topic
Author

How to provide willdcard search

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528

I am having a text field in a JSP page . I want to provide the flexibilityof wildcard search for the users.
How can i extract this data in a servlet ?? (Decided not to use Apache Lucene)
How can i implement this ??



If you want something you never had do something which you had never done
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Certainly there's nothing in either the JSP or Servlet APIs that's going to help with this.

Are you looking for an alternative to Lucene, or information on implementing something like this from scratch?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Questions usually end with only one question mark. Common sense is, the more question marks you add to it, the more (negative) pressure you put on it. I recommend you to stop with this ;)

Regarding to your problem: do it at DB level. Consult the documentation of the DB in question how to do it, then just write SQL accordingly.

This has, again, nothing to do with JSP. It is just a view technology. It has in fact nothing to do with business logic, let alone with databases.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks Bear and Bauke .


Bauke as you mentioned :

I am thinking of how can i go with this at DataBase level ?

Do you suggest me to use getQueryString() method and parse it ??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Database searching is not a JSP topic, so I've moved this post to a more appropriate forum.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
You haven't really said *what* you want to search, but a database search could be as simple as

select * from my_table where my_attribute like '%my_search_term%';


Obviously it gets more complicated if you want to be able to search for more than a single term, or if you want to provide other options. If you tell us the details we may be able to be more specific.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
I want to provide Google implementation like using + symbols , - symbols .For example :

JSP+JDBC (on to google search page)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
And what kind of data is it you want to search - files (what kind?) or database tables or something else? How is the data organized?
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Ulf , Thanks for your replies.

First of all its A normal application for practice purpose.

Coming to the data :

A row which has different columns like Technologies JSP , JDBC , EJB ---- etc.(Oracle 9i as Database)
Now i want to get the names of those persons who know technologies as specified in the TextField .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
OK. Can you write an SQL query for a common case, maybe for "+JDBC +JSP -JMS"? Which columns need to be part of the query, and how would the associated SQL terms for them need to be concatenated?
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
hh
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
select * from person where Tech in (?,?,?)

This assumes that each row has a single attribute "Tech" and that it can have exactly one value. But earlier you said you had different attributes "JDBC", "JSP", "EJB" etc (the value of which I assume would be boolean). Which one of these is it - can you give an example of a row for a person that's listed as "JDBC" and "JSP"?
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
I am sorry the Query is not correct "select * from person where Tech in (?,?,?)" what you said is absolutely correct "his assumes that each row has a single attribute "Tech" and that it can have exactly one value".

i will answer you . Anyway thanks.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Ulf what i want to ask is that Can't we get what is passed in a TextField and parse it and pass it to the SQL Query??

If it contains a + symbol i will use the AND operator .

and if it is - symbol i will use the NOT IN operator.

what do you think??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
Can't we get what is passed in a TextField and parse it and pass it to the SQL Query??
Sure you can, but that has nothing to do with JDBC. Also, not every user can be expected to know what "+" and "-" mean, and to use it correctly. So if you need to support users that are somewhat less than "power users", you should look into providing a more user-friendly UI to these options.

If it contains a + symbol i will use the AND operator .
and if it is - symbol i will use the NOT IN operator.
what do you think??

Sounds workable, but you need to pay attention to trim extra white space (both in the DB and the query terms), and how to handle uppercase/lowercase.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
RaviNada Kiran wrote:
Bauke as you mentioned :

I am thinking of how can i go with this at DataBase level ?

Do you suggest me to use getQueryString() method and parse it ??

Concentrate you on how to do it with pure SQL.
Once done that, concentrate on how to write JDBC code to accomplish this and wrap it in a DAO method.
Once done that, concentrate on how to "convert" user input from request to parameters for the DAO method.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31077
    
233

RaviNada Kiran wrote:Ulf what i want to ask is that Can't we get what is passed in a TextField and parse it and pass it to the SQL Query??

If it contains a + symbol i will use the AND operator .

and if it is - symbol i will use the NOT IN operator.

what do you think??

Make sure you are still using a PreparedStatement. Otherwise someone could pass something like "=a ' ; delete from table ; ' and you could be the victim of a SQL injection attack.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to provide willdcard search