Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to check if Radio Buttons and Checkboxes have data  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Queries

You will have to build a dynamic query statement. My advice would be to start with a basic query string: "select * from customers ". Then, if the name and/or City textfields have data in them, add SQL text to your query string. For example, in the second screen above, the final query string would be:

select * from customers where city like 'Tampa%' order by zip

If the user entered 'Forth' for the name, and 'T' for the city, then the query would look like:

select * from customers where name like 'Forth%' and city like 'T%' order by name

Note that I'm using 'like' in the where clause. This means that the query will look for names starting with 'Forth', and cities starting with 'T' -- Tampa in our db.

Also remember to include the logical AND if both name and city textfields are selected. Otherwise, the where clause does not include any logical operator.

Once you have your query string built, you can then execute it. (a executeQuery statement is fine). Loop through the result set and build a nice formatted string for each result, which you will then append to the text area using the appendText() method.

https://gyazo.com/595e7759ac930befc21f871a69f8f6c8

https://gyazo.com/595e7759ac930befc21f871a69f8f6c8https://gyazo.com/14aff4a0e0b6855232927832e4039743

What I have tried:

I have the querey statement

I am just not sure how to check if field and radiobuttons have data, and how would I makea string and add to the statement if they have data in the fields.
Staff note (Knute Snortum):

A note about your post: be sure to use an expressive subject line. Just "Java" doesn't tell use what problem you're trying to solve. I have created a subject line for you this time.

 
Rancher
Posts: 624
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your 2nd link dosn't work and I think this should be in the javaFX forum or what did you use to make your gui?
If you use javaFx you can asign an id to your radiobuttons and us the isCheckedMethod, when it is checked you can pass the value to your repository to put in the query
 
Saloon Keeper
Posts: 2156
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like homework.

Post the code that you are having problems with so that we have a better idea of where you are getting stuck, what fields and radiobuttons you are referring to.
 
Ron McLeod
Saloon Keeper
Posts: 2156
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!  
 
Ankit Pai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the database, I also used JavaFx to make a GUI, I used two textfields and a group of three radiobuttons in a togglegroup

 
Ankit Pai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the 2nd link that was not working.

https://gyazo.com/14aff4a0e0b6855232927832e4039743
 
Daniel Demesmaecker
Rancher
Posts: 624
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't put everything in your main method, you should create dao's...
 
Ankit Pai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was planning on making methods, but I'm trying to figure out how to get data from textfield and radiobuttons and add the string to the query statement
 
Daniel Demesmaecker
Rancher
Posts: 624
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not working code, just to give you an idea.

controllerClass:

 
Daniel Demesmaecker
Rancher
Posts: 624
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a prepared statement to add the variables in your querry
 
Ankit Pai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, how would I add that string to the Query Statement?
 
Ankit Pai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you give me an example of a prepared statement?
 
Sheriff
Posts: 5469
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
 
Daniel Demesmaecker
Rancher
Posts: 624
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ankit Pai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would I have to do, in order to do this ?

Then, if the name and/or City textfields have data in them, add SQL text to your query string. For example, in the second screen above, the final query string would be:
 
Daniel Demesmaecker
Rancher
Posts: 624
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't like the fact that everyone post and just expects you to solve it for them, especially when it's an assignment.
We gave you the tools, now it only takes a litle bit of elbowgreace to figure it out...
 
Ankit Pai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Sir, the thing is im trying to understand how
 
Daniel Demesmaecker
Rancher
Posts: 624
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I would start by folowing a tutorial.
Write a dao (interface) were you write your methods you'll need in your program, then make an implementation of that dao writting out all your querries.

I'll give you one example:

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!