项目摘要:我有一个Web应用程序,它应该将Addresses添加到数据库中。
我有这个堆栈跟踪:
20:07:37,530 ERROR [stderr] (default task-43) java.sql.SQLException: Column count doesn't match value count at row 1
20:07:37,530 ERROR [stderr] (default task-43) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
20:07:37,530 ERROR [stderr] (default task-43) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
20:07:37,530 ERROR [stderr] (default task-43) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
20:07:37,530 ERROR [stderr] (default task-43) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
20:07:37,530 ERROR [stderr] (default task-43) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
20:07:37,530 ERROR [stderr] (default task-43) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
20:07:37,531 ERROR [stderr] (default task-43) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
20:07:37,531 ERROR [stderr] (default task-43) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
20:07:37,531 ERROR [stderr] (default task-43) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485)
20:07:37,531 ERROR [stderr] (default task-43) at ch.bbw.addressbook.AddressDAO_Database.create(AddressDAO_Database.java:60)
20:07:37,531 ERROR [stderr] (default task-43) at ch.bbw.addressbook.AddressService.registerAddress(AddressService.java:34)
20:07:37,531 ERROR [stderr] (default task-43) at ch.bbw.addressbook.AddressService$Proxy$_$$_WeldClientProxy.registerAddress(Unknown Source)
20:07:37,531 ERROR [stderr] (default task-43) at ch.bbw.addressbook.AddressViewController.saveAddress(AddressViewController.java:38)
20:07:37,531 ERROR [stderr] (default task-43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
20:07:37,531 ERROR [stderr] (default task-43) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
20:07:37,531 ERROR [stderr] (default task-43) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
20:07:37,531 ERROR [stderr] (default task-43) at java.lang.reflect.Method.invoke(Unknown Source)
20:07:37,531 ERROR [stderr] (default task-43) at javax.el.ELUtil.invokeMethod(ELUtil.java:300)
20:07:37,531 ERROR [stderr] (default task-43) at javax.el.BeanELResolver.invoke(BeanELResolver.java:415)
20:07:37,531 ERROR [stderr] (default task-43) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
20:07:37,531 ERROR [stderr] (default task-43) at com.sun.el.parser.AstValue.invoke(AstValue.java:285)
20:07:37,531 ERROR [stderr] (default task-43) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
20:07:37,531 ERROR [stderr] (default task-43) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
20:07:37,531 ERROR [stderr] (default task-43) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
20:07:37,532 ERROR [stderr] (default task-43) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
20:07:37,532 ERROR [stderr] (default task-43) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
20:07:37,532 ERROR [stderr] (default task-43) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
20:07:37,532 ERROR [stderr] (default task-43) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
20:07:37,532 ERROR [stderr] (default task-43) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
20:07:37,532 ERROR [stderr] (default task-43) at javax.faces.component.UICommand.broadcast(UICommand.java:315)
20:07:37,532 ERROR [stderr] (default task-43) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
20:07:37,532 ERROR [stderr] (default task-43) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
20:07:37,532 ERROR [stderr] (default task-43) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
20:07:37,532 ERROR [stderr] (default task-43) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
20:07:37,532 ERROR [stderr] (default task-43) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
20:07:37,532 ERROR [stderr] (default task-43) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
20:07:37,532 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
20:07:37,533 ERROR [stderr] (default task-43) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
20:07:37,533 ERROR [stderr] (default task-43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
20:07:37,534 ERROR [stderr] (default task-43) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
20:07:37,534 ERROR [stderr] (default task-43) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
20:07:37,535 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
20:07:37,535 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
20:07:37,535 ERROR [stderr] (default task-43) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
20:07:37,535 ERROR [stderr] (default task-43) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
20:07:37,535 ERROR [stderr] (default task-43) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
20:07:37,535 ERROR [stderr] (default task-43) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
20:07:37,535 ERROR [stderr] (default task-43) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
20:07:37,535 ERROR [stderr] (default task-43) at java.lang.Thread.run(Unknown Source)
这是我的create()方法,它将值插入表:
public void create(Address address) {
// TODO: create, not implemented yet
try {
stmt = connection.createStatement();
stmt.executeUpdate("INSERT INTO address(id, firstname, lastname, phoneNumber, mail, cat, registrationDate) " + "VALUES (" +address.getId()+ ",'" +address.getFirstname()+ "','" +address.getLastname()+ "','" +address.getPhonenumber()+ "','" +address.getMail()+ "','" +address.getCat()+ "','" +address.getRegistrationDate().toString()+ "')");
connection.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这里是为了更好地帮助地址Java类:
import java.util.Date;
public class Address {
private int id;
private String firstname;
private String lastname;
private String phonenumber;
private String mail;
private String cat;
private Date registrationDate;
public Address(int id, String firstname, String lastname, String phonenumber, String mail, String cat) {
//this(id, firstname, lastname, phonenumber, mail, cat, new Date());
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
this.phonenumber = phonenumber;
this.mail = mail;
this.cat = cat;
this.registrationDate = new Date();
}
public Address(int id, String firstname, String lastname, String phonenumber, String mail, String cat,
Date registrationDate) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
this.phonenumber = phonenumber;
this.mail = mail;
this.cat = cat;
this.registrationDate = registrationDate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getCat() {
return cat;
}
public void setCat(String cat) {
this.cat = cat;
}
public Date getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
}
}