Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert sql with jsp 1

Status
Not open for further replies.

sensory21

Programmer
Jan 27, 2004
79
GB
Hi,

I am just starting to learn jsp, have used php before. I've got a jsp file with input boxes corresponding to my sql fields in my table, in the same file I've got the query to insert the results in the db, the query is working but each time I reload the page it also adds a record in the db?
or if I press the other button i.e Reset it does the same thing. I would know what to do with php but I don't with jsp, can someone help please?

Cheers
Vero
 
Because each time you reload your JSP, you are causing it to execute your insert statement ...
 
Thanks Sedj,

I know that but could you tell me how not to then?

Like in php if you have a submit button called Add then you can say
if $Add then .... do or don't..

but with jsp how do you do it?
 
Well, you may think about having one jsp for displaying records, and another for inserting them.

Why don't you post your code so we can have a better idea of what you are trying to do ...
 
Hi,

Execute the Query only when there is an Action on the Page insted of every time as sedj said.

Check for the requestParameter("submit"); if it is null then donot execute the SQL statement.

I am using parameter name as submit for submit button in html form.

<%
if(null != requestParameter(&quot;submit&quot;))
{
// execute your SQL statment
}
// display your html form
%>

Cheers,
Venu
 
Cheers, last night I've started to find a solution with if else but that was too long I thought there was a better idea, thanks for the advice of the submit button.

Vero
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top