Foros del Web » Programación para mayores de 30 ;) » Java »

! MYSQL Exception: Column count doesn't match value count at row 1

Estas en el tema de ! MYSQL Exception: Column count doesn't match value count at row 1 en el foro de Java en Foros del Web. Porque me sale este error ?: ! MYSQL Exception: Column count doesn't match value count at row 1 cuando compilo la siguiente clase : import ...
  #1 (permalink)  
Antiguo 10/12/2014, 09:39
 
Fecha de Ingreso: diciembre-2014
Mensajes: 4
Antigüedad: 9 años, 4 meses
Puntos: 0
Pregunta ! MYSQL Exception: Column count doesn't match value count at row 1

Porque me sale este error ?:
! MYSQL Exception: Column count doesn't match value count at row 1

cuando compilo la siguiente clase :

import java.io.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;
public class PedidosDB extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();



String telbestell_id = req.getParameter("tpedido_id");
String telkunde_id=req.getParameter("tusuario_id");
String teldatum= req.getParameter ("tdate");
String telpreis= req.getParameter ("tprecio");




//DB-Treiber
try
{
Class.forName("org.gjt.mm.mysql.Driver");
}
catch( ClassNotFoundException e)
{
out.println("DB-Treiber nicht da!");
}
//Connection
try
{

Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/dy36","dy36","bmAx");
Statement st = con.createStatement();
try
{
st.executeUpdate("drop table if exists PEDIDO;");

}
catch(Exception e)
{
out.println("Problem mit: DROP TABLE PEDIDO!");

}




st.executeUpdate("create table PEDIDO(pedido_id int(10) NOT NULL AUTO_INCREMENT, usuario_id int(10), date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,preicio int(11) NOT NULL,PRIMARY KEY (pedido_id))");






st.executeUpdate("insert into Person values ('"+telprecio+"')");




out.println("<html><head><title>PEDIDO</title></head>");
out.println("<body>******PEDIDO*******<hr><br>");
out.println("<TABLE Border=10 CellPadding=5><TR>");
out.println("<th>PEdidoID</th><th>usuario_id</th><th>Date</th><th>Precio</th></TR>");


ResultSet rs = st.executeQuery("select * from PEDIDO");
while(rs.next())
{

String spedido_id= rs.getString("pedido_id");
String susuario_id = rs.getString("usuario_id");
String sdate=rs.getString("");
String spreis=rs.getString("Preis");



out.println("<TR>");

out.println("<TD>"+sbestell_id+"</TD>");

out.println("<TD>"+ skunde_id+ "</TD>" );

out.println("<TD>"+ sdatum +"</TD>" );

out.println("<TD>"+ spreis +"</TD>" );




out.println("</TR>");




}
out.println("</TR>"); // fin while
out.println("</TABLE></CENTER></DIV></HTML>");



st.close();
con.close();
}
catch(Exception e)
{
out.println ("! MYSQL Exception: "+e.getMessage());
}
}

public void doPut(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doGet(req,res);
}
}
  #2 (permalink)  
Antiguo 10/12/2014, 13:56
Avatar de Profesor_Falken  
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 8 meses
Puntos: 182
Respuesta: ! MYSQL Exception: Column count doesn't match value count at row 1

Buenas,

Creas la tabla PEDIDO:
Código SQL:
Ver original
  1. st.executeUpdate("create table PEDIDO(pedido_id int(10) NOT NULL AUTO_INCREMENT, usuario_id int(10), date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,preicio int(11) NOT NULL,PRIMARY KEY (pedido_id))");

Y justo después le haces un select?
Código SQL:
Ver original
  1. ResultSet rs = st.executeQuery("select * from PEDIDO");

Eso no tiene sentido porque nunca va a tener filas.
Tambíen intentas aceder luego a columnas que no existen:

Código SQL:
Ver original
  1. String sdate=rs.getString("");
  2. String spreis=rs.getString("Preis");

Ese error que posteas se produce al realizar un Insert, por lo que lo más posible es que se produzca en esta linea

Código SQL:
Ver original
  1. st.executeUpdate("insert into Person values ('"+telprecio+"')");

¿La tabla Person solo tiene un campo?


Un saludo
__________________
If to err is human, then programmers are the most human of us

Etiquetas: mysql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:56.