Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing search on different JtextFields in Netbeans

 
chris uchime
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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:
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11337
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank for the reply...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic