If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > LIKE and PreparedStatement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-21-07, 12:18
CrazyTn CrazyTn is offline
Registered User
 
Join Date: May 2007
Posts: 24
LIKE and PreparedStatement

Hello,

I am trying to search for a name, so that the user only need to input part of the name and it will come up.

firstname LIKE '%?%';

ps.setString(1, firstname);

The statement sees the '?' as part of the String to be search, so is there any commands to say that the '?' is used for a preparedstatement and not part of the search string?
Reply With Quote
  #2 (permalink)  
Old 06-21-07, 12:43
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
What is the RDBMS you are using please? I will then move the thread to the appropriate forum and you will likely get an answer.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 06-21-07, 12:56
CrazyTn CrazyTn is offline
Registered User
 
Join Date: May 2007
Posts: 24
postgreSQL using java
Reply With Quote
  #4 (permalink)  
Old 06-21-07, 15:49
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
TBH I don't know if this is a java question or a PostgreSQL question.

Moving to PostgreSQL - let me know if it should be java.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #5 (permalink)  
Old 06-21-07, 16:31
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
I would say that it's probably a java issue.

PostgreSQL uses ANSI standard like wildcards for text searches

% = any number of characters,
_ = 1 character.

ref http://www.postgresql.org/docs/8.2/s...-matching.html

and

http://java.sun.com/docs/books/tutor.../prepared.html
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Last edited by loquin; 06-21-07 at 16:42.
Reply With Quote
  #6 (permalink)  
Old 06-21-07, 17:08
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
BTW. I know virtually nothing about Java, but from perusing the java documentation, it appears that you may not want to use the apostrophes (string/date delimiters) in your SQL in a prepared statement. And, if that's the case, you might need to concatenate the wildcard character(s) to the text in the .setstring method call.

ps.setString(1, "%" + firstname + "%");
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Last edited by loquin; 06-21-07 at 17:13.
Reply With Quote
  #7 (permalink)  
Old 06-21-07, 22:41
CrazyTn CrazyTn is offline
Registered User
 
Join Date: May 2007
Posts: 24
Quote:
Originally Posted by loquin
BTW. I know virtually nothing about Java, but from perusing the java documentation, it appears that you may not want to use the apostrophes (string/date delimiters) in your SQL in a prepared statement. And, if that's the case, you might need to concatenate the wildcard character(s) to the text in the .setstring method call.

ps.setString(1, "%" + firstname + "%");
Thanks I ll try it out, seems safe to do it this way,
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On