Hi
I am running an jsp application thru which the values are saved in mysql. all values are saved twice.Pls help me how to avoid that
Hi
I am running an jsp application thru which the values are saved in mysql. all values are saved twice.Pls help me how to avoid that
Cross-posting (as pointed out) is a separate etiquette issue and does not cause duplicate rows. The usual technical causes for “values saved twice” are that the same INSERT runs twice: a browser POST is resubmitted on refresh (or double-click), client-side code triggers two submits, or server-side logic executes the insert more than once (for example, a JSP with DB code being included/forwarded or an insert called twice inside a loop).
Quick diagnostic steps and fixes:
onclick and onsubmit handlers that submit).// after successful insert in a servlet
response.sendRedirect("success.jsp"); <form method="post" onsubmit="this.submitBtn.disabled=true;">
<input type="submit" name="submitBtn" value="Send"/>
</form> executeUpdate() call:try (Connection conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement("INSERT INTO users(name,email) VALUES(?,?)")) {
ps.setString(1, name);
ps.setString(2, email);
ps.executeUpdate();
} Defensive DB measure:
ALTER TABLE users ADD CONSTRAINT uniq_user UNIQUE (name, email); Best practice: move DB code out of JSPs into a servlet/DAO, log the insert call, apply PRG, and add a DB uniqueness constraint. These steps will reveal whether the problem is client-side, server-side, or purely data integrity related, and will stop repeat inserts while the root cause is fixed.
Jump to Post— masijade 1,351FYI Also posted here.
@OP If you are going to cross-post, please at least have the decency to say that and post the links to all in all of the threads, as well as providing summarys of what has happened from …
FYI Also posted here.
@OP If you are going to cross-post, please at least have the decency to say that and post the links to all in all of the threads, as well as providing summarys of what has happened from time to time. No one likes to waste their time making suggestions others have already made. You should be wasting yours keeping everybody else abreast of what you've already been advised. It's only common decency.
Now, add links to any other cross-post you may have, please.
Actually i thought that daniweb and java forums r 2 different forums. so i posted my query in both so that i can get reply in any of these two. and i know the decency. pls dont teach me.
Actually i thought that daniweb and java forums r 2 different forums. so i posted my query in both so that i can get reply in any of these two. and i know the decency. pls dont teach me.
They are two different forums, but how does that change things? It might make it harder for anyone to know that they have wasted their time, but they will still have wasted it. So maybe you don't "know the decency" and I do need to teach you.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.