This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing parameters values with db values

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) I am trying to compare the db value with user values with parameter received from user
2) if the value exists then ignore and insert the values that not exists in the db

Please check my code and help. Thanks in anticipation

===============
My code output:
===============
Already Exists: "1"
1" Not exists
1" Not exists
1" Not exists
3" Not exists
3" Not exists
Already Exists: "3"
3" Not exists
2" Not exists
Already Exists: "2"
2" Not exists
2" Not exists

 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the question?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Respected Sir,

I want to insert values in the database that not exists by ignoring already existing values

javascript:emoticon('');
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Farakh khan wrote:I want to insert values in the database that not exists by ignoring already existing values

You can create a list of values that are not in the database and insert them at the end.

Or you can use the merge statement to do an insert if the value is not there. I don't think you can print out whether the value was found with this approach though.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:
Farakh khan wrote:I want to insert values in the database that not exists by ignoring already existing values

You can create a list of values that are not in the database and insert them at the end.

Or you can use the merge statement to do an insert if the value is not there. I don't think you can print out whether the value was found with this approach though.


Thanks for your reply

The task is to show the end user values that already exists in the database that's why I am insisting for it.

Can we not control it programmatically instead of SQL?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Farakh khan wrote:
Jeanne Boyarsky wrote:
Farakh khan wrote:I want to insert values in the database that not exists by ignoring already existing values

You can create a list of values that are not in the database and insert them at the end.

Or you can use the merge statement to do an insert if the value is not there. I don't think you can print out whether the value was found with this approach though.


Thanks for your reply

The task is to show the end user values that already exists in the database that's why I am insisting for it.

Can we not control it programmatically instead of SQL?


1) MERGE is not working in this case as it comparing existing two values of the database i.e. comparing two tables or two columns

2) I have to show the existing values in my program according to my task.

Please help me

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you have to show the user the values, you wouldn't use MERGE. Instead loop through your result (like you do now) and store the values that you need to insert in a list. Then run another query to insert those values.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Since you have to show the user the values, you wouldn't use MERGE. Instead loop through your result (like you do now) and store the values that you need to insert in a list. Then run another query to insert those values.


Thanks Sir for your reply

I am trying to do the same but where I am making mistake in my code. Can you please check my posted code?

Thanks & best regards
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Farakh khan wrote:
Jeanne Boyarsky wrote:Since you have to show the user the values, you wouldn't use MERGE. Instead loop through your result (like you do now) and store the values that you need to insert in a list. Then run another query to insert those values.


Thanks Sir for your reply

I am trying to do the same but where I am making mistake in my code. Can you please check my posted code?

Thanks & best regards


 
Somnath Mallick
Ranch Hand
Posts: 482
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the full code?

I saw something like expertise.length in your code... but i did not see any expertise variable declared anywhere!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Farakh khan wrote:Thanks Sir for your reply

Just want to point out that I'm female.

Farakh khan wrote:I am trying to do the same but where I am making mistake in my code. Can you please check my posted code?

Your originally code needs a list to keep track of the values to insert. Then it would loop through that list and do the inserts. Why not try to add these two parts and posting the new code?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic