dies der FabricanteEditController ist:funktionieren nicht bearbeiten Frühjahr mvc crud jdbctemplate
package Controller;
import Modelo.Conectar;
import Modelo.Fabricante;
import Modelo.FabricanteValidar;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;
/**
*
* @author x2010s
*/
@Controller
@RequestMapping("fabricanteedit.htm")
public class FabricanteEditController {
FabricanteValidar fabricanteValidar;
private JdbcTemplate jdbcTemplate;
public FabricanteEditController()
{
this.fabricanteValidar=new FabricanteValidar();
Conectar con=new Conectar();
this.jdbcTemplate=new JdbcTemplate(con.conectar());
}
@RequestMapping(method=RequestMethod.GET)
public ModelAndView form(HttpServletRequest request)
{
ModelAndView mav=new ModelAndView();
int id=Integer.parseInt(request.getParameter("id"));
Fabricante datos=this.selectFabricante(id);
mav.setViewName("fabricanteedit");
mav.addObject("fabricante",new Fabricante(id,datos.getNombre(),datos.getDireccion(),datos.getTelefono(),datos.getTipo()));
return mav;
}
@RequestMapping(method=RequestMethod.POST)
public ModelAndView form
(
@ModelAttribute("fabricante") Fabricante f,
BindingResult result,
SessionStatus status,
HttpServletRequest request
)
{
this.fabricanteValidar.validate(f, result);
if(result.hasErrors())
{
ModelAndView mav=new ModelAndView();
int id=Integer.parseInt(request.getParameter("id"));
Fabricante datos=this.selectFabricante(id);
mav.setViewName("fabricanteedit");
mav.addObject("fabricante",new Fabricante(id,datos.getNombre(),datos.getDireccion(),datos.getTelefono(),datos.getTipo()));
return mav;
}else
{
int id=Integer.parseInt(request.getParameter("id"));
this.jdbcTemplate.update(
"update fabricante "
+ "set nombre=?,"
+ "direccion=?,"
+ "telefono=? "
+ "tipo=? "
+ "where "
+ "id=? ",
f.getNombre(),f.getDireccion(),f.getTelefono(),f.getTipo(),id);
return new ModelAndView("redirect:/fabricante.htm");
}
}
public Fabricante selectFabricante(int id)
{
final Fabricante maker = new Fabricante();
String quer = "SELECT * FROM fabricante WHERE id="+id;
return (Fabricante) jdbcTemplate.query
(
quer, new ResultSetExtractor<Fabricante>()
{
public Fabricante extractData(ResultSet rs) throws SQLException, DataAccessException {
if (rs.next()) {
maker.setNombre(rs.getString("nombre"));
maker.setDireccion(rs.getString("direccion"));
maker.setTelefono(rs.getString("telefono"));
maker.setTipo(rs.getString("tipo"));
}
return maker;
}
}
);
}
}
Dies ist die Ansicht fabricanteedit.jsp
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Editar Fabricante</title>
<link href="css/estilos.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet" >
</head>
<body>
<div class="container">
<ol class="breadcrumb">
<li><a href="<c:url value="/fabricante.htm" />">Listado de fabricante</a></li>
<li class="active">Editar</li>
</ol>
<div class="panel panel-primary">
<div class="panel-heading">Editar</div>
<div class="panel-body">
<form:form method="post" commandName="fabricante">
<h1>Complete el formulario</h1>
<form:errors path="*" element="div" cssClass="alert alert-danger" />
<p>
<form:label path="nombre">Nombre: </form:label>
<form:input path="nombre" cssClass="form-control" />
</p>
<p>
<form:label path="direccion">Direccion</form:label>
<form:input path="direccion" cssClass="form-control" />
</p>
<p>
<form:label path="telefono">Telefono</form:label>
<form:input path="telefono" cssClass="form-control" />
</p>
<p>
<form:label path="tipo">Tipo</form:label>
<form:input path="tipo" cssClass="form-control" />
</p>
<hr />
<input type="submit" value="Enviar" class="btn btn-danger" />
</form:form>
</div>
</div>
</div>
</body>
meiner Datenbank Derby ist.
wenn ein Hersteller zu bearbeiten versuchen, der folgende Fehler auftritt:
HTTP-Status 500 - Interner Serverfehler
Typ Ausnahmebericht
messageInternal Server Error
DescriptionThe Server hat einen internen Fehler, der es daran hinderte, diese Anfrage zu erfüllen.
Ausnahme
org.springframework.web.util.NestedServletException: Request-Verarbeitung fehlgeschlagen; verschachtelte Ausnahme ist org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; schlechte SQL-Grammatik [Update fabricante Satz nombre = ?, direccion = ?, Telefono = ?, tipo = ?, wo id =? ]; nested Ausnahme ist java.sql.SQLSyntaxErrorException: Fehler de sintaxis: Fand "where" in Zeile 1, Spalte 64.
Ursache
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; schlechte SQL-Grammatik [Update fabricante Satz nombre = ?, direccion = ?, Telefono = ?, tipo = ?, wo id =? ]; nested Ausnahme ist java.sql.SQLSyntaxErrorException: Fehler de sintaxis: Fand "where" in Zeile 1, Spalte 64.
Ursache
java.sql.SQLSyntaxErrorException: Fehler de sintaxis: Fand "where" in Zeile 1, Spalte 64
Ursache
ERROR 42X01: Fehler de sintaxis: Fand "wo" in Zeile 1, Spalte 64
Bitte [Bearbeiten] Sie Ihre Frage Titel zu etwas sinnvoll. Sie haben lediglich die Informationen wiederholt, die bereits in den Tags vorhanden sind. Ihr Titel sollte ein Problem beschreiben oder eine Frage auf eine Weise stellen, die für einen zukünftigen Leser eine Bedeutung hat, wenn er eine Liste von Suchergebnissen betrachtet. Das Wiederholen von Tag-Informationen ist bedeutungslos und nutzlos. Bitte verbringe etwas Zeit mit [tour] und lies die [help] Seiten, insbesondere [ask]. –