• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Implementing search on different JtextFields in Netbeans

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I use NetBeans IDE 7.2 and MS Access 2010

I have this project I'm working on, of which I want to have different JtextFields mapped to differents columns in the database tables I wish to search for records. My problem is I have 4 Jtextfields mapped to 4 columns from two different tables in the database, I want a situation whereby when I type in only one or two Jtextfields and click the search button, it ignores the other empty Jtextfields and gives me the result based on the fields entered. I used the logical operators WHERE AND in the sql statement but when I run the program it gives the error. Java.sql.SQLException: [microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression......
Here is my code:
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's all in the SQL. If you to say only search 1 text field then your where clause should only have 1 condition. If 2 text fields entered, where clause has 2 conditions etc.

So if your program you should dynamically create the where clause based on what text fields are entered. Currently you have all 4 conditions which will definitely only work for all 4 fields are entered.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In future, while posting code, please UseCodeTags. I have added them this time for you. As you can see the tags make the code much more easier to read and understand.
From what information you have shared, your problem is related to the query and not Swing per se. I will move this topic over to a more appropriate forum,
 
chris uchime
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for the reply...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic