The mistery of the double insertion!!!

I can磘 understand why my code sometimes inserts two rows in the database with the same information.See my code:

<%!

Connection conn;

Statement stmt;

Statement stmt2;

Statement stmt3;

String url = "jdbc:postgresql://localhost/trf";

String assunto = " ";

String titulo = " ";

String subTitulo = " ";

int idSecao=0;

int posicao=0;

String inicioValidade = " ";

String fimValidade = " ";

String diaInicio,mesInicio,anoInicio=" ";

String diaFim,mesFim,anoFim=" ";

int indeterminado=0;

String conteudo = " ";

String assinatura = " ";

String email = " ";

int idConteudo=0;

String SQL;

public void OpenConnection()

{

try

{

Class.forName("org.postgresql.Driver");

}

catch(Exception e)

{

System.out.println(e.toString());

}

try

{

conn = DriverManager.getConnection(url,"postgres","postgres");

}

catch(Exception e)

{

System.out.println("N鉶 foi possivel carregar o banco");

}

} // end Openconnection

public void insertConteudo(String assunto,String titulo,String subtitulo,int idsecao,int posicao,String conteudo,String iniciovalidade,String fimvalidade,int indeterminado,String assinatura,String email)

{

try

{

stmt = conn.createStatement(); //connect the statement to the connection

SQL ="insert into conteudo(assunto,titulo,subtitulo,idsecao,posicao,conteudo,iniciovalidade,fimvalidade,indeterminado,assinatura,email) values('" + assunto + "','" + titulo + "','" + subtitulo + "'," + idsecao + "," + posicao + ",'" + conteudo + "','" + iniciovalidade + "','" + fimvalidade + "'," + indeterminado + ",'" + assinatura + "','" +email + "')";

stmt.executeUpdate(SQL);

}

catch(SQLException ee)

{

System.out.println(ee);

}

}

public int getMaxId()

{

int max = 0;

SQL=" ";

try

{

stmt = conn.createStatement(); //connect the statement to the connection

SQL ="select MAX(idconteudo) as MAXID from conteudo";

ResultSet results=stmt.executeQuery(SQL);

results.next();

max = results.getInt("MAXID");

max++;

}

catch(SQLException ee)

{

System.out.println(ee);

}

return max;

}

public void insertChamada(int idConteudo,String[] chamada){

int idChamada=0;

try

{

stmt = conn.createStatement(); //connect the statement to the connection

SQL=" ";

for(int i=0;i<chamada.length;i++){

idChamada = Integer.parseInt(chamada);

SQL="insert into chamada(idconteudo,idconteudochamada) values (" + idConteudo + "," + idChamada + ")";

stmt.executeUpdate(SQL);

}

}

catch(SQLException ee)

{

System.out.println(ee);

}

} //end InsertSecaoUsuario

%>

<%

OpenConnection();

assunto = request.getParameter("edtNome");

titulo = request.getParameter("edtNome2");

subTitulo = request.getParameter("textfield");

idSecao = Integer.parseInt(request.getParameter("select"));

posicao = Integer.parseInt(request.getParameter("select2"));

diaInicio = request.getParameter("select4");

mesInicio = request.getParameter("select5");

anoInicio = request.getParameter("select6");

diaFim = request.getParameter("select7");

mesFim = request.getParameter("select8");

anoFim = request.getParameter("select9");

indeterminado = 1; //Integer.parseInt(request.getParameter("checkbox"));

String[] chamada = request.getParameterValues("select3");

assinatura = request.getParameter("edtNome3");

email = request.getParameter("edtNome4");

inicioValidade = diaInicio+"/"+mesInicio+"/"+anoInicio;

fimValidade = diaFim+"/"+mesFim+"/"+anoFim;

conteudo = request.getParameter("corpoEfetivo");

String thing = "'";

char array[] = new char[1];

thing.getChars(0,1,array,0);

conteudo = conteudo.replace(array[0],'?);

idConteudo=getMaxId();

insertChamada(idConteudo,chamada);

insertConteudo(assunto,titulo,subTitulo,idSecao,posicao,conteudo,inicioValidade,fimValidade,indeterminado,assinatura,email);

conn.close();

stmt.close();

%>

Anyone have any idea?

[4520 byte] By [brunoheliusa] at [2007-9-28 15:14:25]
# 1
>Anyone have any idea? This is a web page? What prevents the user from banging on the button twice?
jschella at 2007-7-12 12:00:10 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...