• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

JDBC search function ?

 
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, if i have 3 fields which use as search keys to find database's data in form,

say field 1 for company name , field2 for company code, and company registration no.

how can i make 3 fields which is flexible enough to detect what to search,

for example , if user keyin only company code , then the search function will baseon search criteria company code ,

if however, user keyin company name and company code, then search will based on two criteria.

and last question, the sql query to let user say keyin only a character like "A" in company code , then it will return all company code with "A" character include in whole company code from database

i have use following query in java code as follow but it give unnecessary return data


comcode, comname and comregno is variable that user have keyin in form's search field.

thank you very much for guidance
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally i followed this way.

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks , Srinivasa , but why you put "1=1" ? why we need to include that ?

and if we have only have one field that user have keyin, then how to solve the query word "AND" ?

thank you
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've been doing some similar searching, and the code I use is in this thread.. Some stuff is probably postgres specific, but the general idea is the same.

No idea if it's a good way to go about it, but it does work.

Good luck.
 
author & internet detective
Posts: 41110
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alvin,
The "1=1" is there in case the code, name and reg no are all null (so the statement will compile/run). Personally, I favor using a boolean flag to see if I need the "and". The first clause doesn't get one and all subsequent clauses do.
reply
    Bookmark Topic Watch Topic
  • New Topic