🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.databases.mssql-l
Article #209

Re: sql search keyword

#209
From: Ingo Pakleppa
Date: Tue, 25 Feb 2003 09:39
31 lines
2322 bytes
On Mon, 24 Feb 2003 13:35:52 +0000, Brad McFarlane wrote:

> exist_world_beyond_yours wrote:
>> 
>> Hello,  I'm trying to search for particular  word inside  VARCHAR (not
>> entire phrase)   but
>> 
>> WHERE
>>    CIRCUIT.TABLE.NAME LIKE :keyword
>> 
>> only work for the entire phrase.  Ex.  " i go to java class" , search
>> key want to be consider match "java"
>> 
>> How do I code it in java?
>> 
>>    ResultSet results = statement.executeQuery("SELECT * FROM
>>    CIRCUIT.TABLE
>> WHERE CIRCUIT.TABLE.NAME LIKE *"+keywordz+"*");  /* doesn't work */
>> 
>> Thank you for reviewing
> 
> IIRC, the SQL wildcard character is "%" not "*", so I'd write the query
> as:
> 
> "SELECT * FROM CIRCUIT.TABLE WHERE CIRCUIT.TABLE.NAME LIKE '%" +
> keywordz + "%'" (and note that the whole pattern is enclosed in single
> quotes).

Actually, I would use a prepared statement. Otherwise, you will have a lot
of problems if keywordz happens to contain a single quote (there are other
ways around that, but prepared statements are generally best).
Technical Details
Message-ID: <9RG6a.9100$2b.446475@news1.west.cox.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!216.166.71.14.MISMATCH!border3.nntp.aus1.giganews.com!nntp.giganews.com!central.cox.net!cox.net!p01!news1.west.cox.net.POSTED!53ab2750!not-for-mail
References: <3e5a621d_1@news.tm.net.my> <3E5A6608.762100A0@alcatel.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10f47b,e6cac314263c9233
X-Google-Attributes: gid10f47b,public
X-Google-Thread: f6611,e6cac314263c9233
X-Google-Attributes: gidf6611,public
X-Google-Thread: f5d71,e6cac314263c9233
X-Google-Attributes: gidf5d71,public
X-Google-ArrivalTime: 2003-02-25 01:39:20 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!216.166.71.14.MISMATCH!border3.nntp.aus1.giganews.com!nntp.giganews.com!central.cox.net!cox.net!p01!news1.west.cox.net.POSTED!53ab2750!not-for-mail
From: "Ingo Pakleppa" <ingo-immigration@kkeane.com>
Subject: Re: sql search keyword
User-Agent: Pan/0.13.0 (The whole remains beautiful)
Newsgroups: bit.databases.mssql-l,comp.databases.ibm-db2,comp.lang.java
References: <3e5a621d_1@news.tm.net.my> <3E5A6608.762100A0@alcatel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Lines: 31
Message-ID: <9RG6a.9100$2b.446475@news1.west.cox.net>
Date: Tue, 25 Feb 2003 09:39:17 GMT
NNTP-Posting-Host: 68.7.157.187
X-Complaints-To: abuse@cox.net
X-Trace: news1.west.cox.net 1046165957 68.7.157.187 (Tue, 25 Feb 2003 04:39:17 EST)
NNTP-Posting-Date: Tue, 25 Feb 2003 04:39:17 EST
Organization: Cox Communications