I have a question that is burning me the coconut, I'm with jsp and mysql Workbench, in one of the tables there is an attribute with an id with autoincremento, At the moment of entering the data from the form, I enter 20 repeated data, the Insert is as follows:
Connection conexion = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conexion = DriverManager.getConnection("jdbc:mysql://localhost/desemb", "root", "");
st = conexion.createStatement();
st.executeUpdate("insert into desembarcos values (null,'"+anio+"','"+mes+"','"+region+"','"+tonelada +"','"+especie+"')");
request.getRequestDispatcher("ingresartipo.jsp").forward(request, response);
conexion.close();
} catch (Exception e) {
}
The null probe it in mysql and it works, it is adding rows with its respective increment, in fact in java if instead of null I force an id with a predetermined value also works correctly, the case is that when putting the null or zero as recommended by the literature in the consultation to work self-increase this gives me 20 equal data, friends need help from the community, it is very rare, what happens.
Thanks for the reply This is the sheet of the code in question, in java does not leave any error when I run the form, just throws me 20 data equal when I put the null or "zero #, to call autoincrement, from mysql I insert and it works correctly. At one time I thought it was a Cartesian product, but that is in the select queries, not in the insert
Disembarkations
<form action="" method="post">
<input type="text" name="especie" placeholder="nombre especie">
<input type="text" name="anio" placeholder="año">
<input type="text" name="mes" placeholder="mes">
<input type="text" name="region" placeholder="region">
<input type="text" name="tonelada" placeholder="tonelada">
<input type="submit" name="ingresar" value="Ingresar">
</form>
<%
if (request.getParameter("ingresar") != null) {
int especie = Integer.parseInt(request.getParameter("especie"));
int anio = Integer.parseInt(request.getParameter("anio"));
String mes = request.getParameter("mes");
String region = request.getParameter("region");
int tonelada = Integer.parseInt(request.getParameter("tonelada"));
int con = 0;
Connection conexion = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conexion = DriverManager.getConnection("jdbc:mysql://localhost/desemb", "root", "");
st = conexion.createStatement();
st.executeUpdate("insert into desembarcos values (null,'"+anio+"','"+mes+"','"+region+"','"+tonelada +"','"+especie+"')");
request.getRequestDispatcher("ingresartipo.jsp").forward(request, response);
conexion.close();
} catch (Exception e) {
}
}
%>
</body>