Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a function to insert record in 'user' table (mysql db). This user table has only 'id' primary field with auto increment and no any other field is unique, but In program I am checking if value of a field (let say for example the field is 'username') is exist then don't insert record. But the I am getting duplication record because the Two requests are coming to the server at same time (I am also saving the creation time in (creation_date) field). When I am manually inserting the record one by one then It Works perfect but using program or JMeter testing tool firing the multiple request at the same time then duplicate record found in table.

I can make username unique field but in my situation unique key length exceeds the key length.

Any other Solution please suggest.
Posted

1 solution

you will need to deep dive into database theory. your problem is that data is not yet written while new data is already requested, resulting in an "old" database set is being send. There are a lot of pattern to solve your problem, like a synchronized queuing pool e.g. doing on request per time using only on db connection, another one is using transactions, etc.

you might lack a lot of knowledge for this task (sorry, no offense).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900