• Post Reply Bookmark Topic Watch Topic
  • New Topic

PreparedStatment - Search Page

 
arunkumar subramanian
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a search page with some text boxes (empno, ename, designation, deptno) where the user can enter some values to search. How to create a prepared statement for this search?


[edited to add line break]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35716
410
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to use some if statements to append just the entered fields in the query.
 
Ryan Webb
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this.



hope this helps!
Ryan Webb
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35716
410
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan,
That won't work. SQL requires "and" rather than "," to separate commas.



The reason I didn't suggest this is it implies all of the fields were entered. If any are optional, Arunkumar needs to write logic to concatenate the relevant parts of the where clause.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!