Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

how to do validation part in java , i have 5 fields i need verify validation for all these 5 fields

Hi here i have total 5 fields,all these are not mandatory fields
From UI end i am selecting these values clicking on submit button.
i can select any of the field and inserting into DB,once the value inserted in DB,It should not accept the value again.
The below are the fields:
1.state
2.pid
3.kst
4.DM
5.ped

now from the application i am selecting the state value and clicking submit button
here i am checking the condition

if(state!=null and pid==null and kst==null and DM==null and ped==nul){
	 if{
	//here i am checking these values are already there in DB or not
	//if values are not there in DB then i am inserting these values into respective table.
	}
}else if(...)
{
}

Open in new window

like this i need to check all the scenarios
i have  total 5 fields
here i am seeing total 16 scenarios how can i check all the possible scenarios
i can use else if conditions upto all 16 scenarios but is there any logic to use all the scenarios in short form
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

here i am seeing total 16 scenarios how can i check all the possible scenarios
Why do you need to?

Please also post the table definition
It seems to me that whatever the combination is you can do the same check:
check if a record having the given values for state, pid, kst, DM and ped is already in the table.
Or do I understand this wrong?
Avatar of srikotesh
srikotesh

ASKER

i am  doing the same but i need to keep more else if blocks

For this i did one alternative

if(condition 1 || condition2 || condition3 || condition 4){	
	//here i am checking db validation as well (conditon1 ||conditon2 ||condition3 ||condition4)
}else if( condition5 || condition6 || condition 7 || condition 8){	
	//here i am checking db validation as well (conditon4 ||conditon5 ||condition6 ||condition7 ||condition 8)
}

Open in new window


by using or condition i cut down many else if blocks
With that pseudo-code, it's very difficult to tell whether that's valid or even necessary. Generally what are these conditions?
Indeed some more specifics would help a lot. The more specific you are the better we can help you.
eg. in your code

if(state!=null and pid==null and kst==null and DM==null and ped==nul){
	 if{
	//here i am checking these values are already there in DB or not
	//if values are not there in DB then i am inserting these values into respective table.
	}
}

Open in new window


what does "checking these values are already in DB or not" mean.
Do you check if "a record with state = the given state and the 4 other fields = null" exists or what?
in the earlier post i have gave the scenario
let suppose condition1 means
if((state!=null and pid==null and kst==null and DM==null and ped==nul)||(state!=null and pid!=null and kst==null and DM==null and ped==null){
            //if(condition1)or (condition2)
            let suppose from ui screen i entered only state and rest of the fields are null
            at that time condition1 vl satisfy and it vl go inside
            and one more scenario ivl give the value like state and pid that second condition vl satisfy
I understand very well that if you enter only state in the UI that the condition1 is true.
And that if you enter state and pid then the condition2 is true. (after all, I can read java code ;-)
And I understand that you don't want to write 16 if statements to cover all possible scenarios.
But to know if you can group some of the 16 conditions together, I try to understand what is inside those if statements
If I don't know that, I can't help. Sorry.
In other words: please explain as detailed as possible what this does:
>>      //here i am checking these values are already there in DB or not
>>      //if values are not there in DB then i am inserting these values into respective table.


Also, you still didn't answer CEHJ's question:
>> Please also post the table definition

Kind advise:
If you want us to help you, please answer our questions, or tell us why you (think) that's an irrelevant question.
But don't just neglect them or experts will do the same with your question.
Hi CEHJ,

These all 5 fields not in the same table
it is the combination of 3 tables
i am using the query and with these 3 table and fecthing the values

it is not possible for me to provide complete table information
i completed this task by placing or(||).
You'd have probably simplified the code (and readability) by using EnumSet
HI CEHJ,
could u plz explore how to use Enumset
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks :) i will try to implement this
I've requested that this question be closed as follows:

Accepted answer: 500 points for CEHJ's comment #a40285344

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.