/    Sign up×
Community /Pin to ProfileBookmark

How to avoid inserting multiple records

I want to know how to avoid inserting multiple records. Below is my case;

(1) I have a jsp page – when a timer for a particular product reaches 3 mins, i am getting that particular productid and sending the productid through ajax

(2) in the ajax script, i am getting the product id and redirecting to a jsp page

(3) in that jsp page, i am inserting a record to a table for that particular productid. Everything works fine, but many records are inserting, i just want to insert only one record.

It would be great if any one can help on how to stop or avoid inserting multiple records.

Thanks,

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mavigozlerNov 10.2010 — Based on your very general, undetailed description, I might look for the following:

  • 1. The database is accepting insertion of the same record, so apparently your database has no primary key?? or you would not get multiple record insertion. That might be a trouble point for you in the future.


  • 2. Your Ajax script tests for an HTTP Response to the request, and it is probably getting some indication of failure and re-sending it. You need to examine both the request and response headers to see what might be happening. Your JSP doc that receives the request may not be properly closing or exiting despite successfully interacting/processing the data with your db. If you fail to do something like "return true", "return 0", or exit (0) at the end of the script or formatting the HTTP response---not being familiar with JSP, I can't say---this could result in the craziness of inserting multiple records and your Ajax/XMLHttpReqObj not getting the report that everything's okay.
  • ×

    Success!

    Help @pradeepktg spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...