我正在尝试将记录插入表中,但出现以下错误: 我也试过使用“?”对于sql语句中的参数,得到同样的错误。
错误
54080 [http-8084-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'Sybase'
54080 [http-8084-2] INFO org.springframework.jdbc.support.SQLErrorCodesFactory - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
54080 [http-8084-2] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - Looking up default SQLErrorCodes for DataSource [org.apache.commons.dbcp.BasicDataSource@1e20a9a]
54083 [http-8084-2] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
54085 [http-8084-2] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
54085 [http-8084-2] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - Database product name cached for DataSource [org.apache.commons.dbcp.BasicDataSource@1e20a9a]: name is 'MySQL'
54090 [http-8084-2] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - SQL error codes for 'MySQL' found
54090 [http-8084-2] DEBUG org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with Error code '0', will now try the fallback translator
54091 [http-8084-2] DEBUG org.springframework.jdbc.support.SQLStateSQLExceptionTranslator - Extracted SQL state class 'S1' from value 'S1009'
54092 [http-8084-2] INFO com.crimetrack.jdbc.JdbcOfficersDAO - PreparedStatementCallback; SQL [INSERT INTO crimetrack.tblofficers (userName,password, fName, lName, oName, divisionNo, poisitionId, emailAdd, startDate, endDate, genderId, phoneNo, dob) VALUES (:userName,:password, :fName, :lName, :oName, :divisionNo, :poisitionId, :emailAdd, :startDate, :endDate, :genderId, :phoneNo, :dob)]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
54092 [http-8084-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Method [handleRequest] returned [ModelAndView: reference to view with name 'officer_registration'; model is null]
54092 [http-8084-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'officer_registration'; URL [/WEB-INF/jsp/officer_registration.jsp]] in DispatcherServlet with name 'crimetrack'
JdbcOfficersDAO
public void saveOfficer(Officers officer) {
logger.info("In saveOfficer");
try{
String sql= "INSERT INTO crimetrack.tblofficers (userName,password, fName, lName, oName, " +
"divisionNo, poisitionId, emailAdd, startDate, endDate, genderId, " +
"phoneNo, dob) VALUES (:userName,:password, :fName, :lName, :oName, :divisionNo, "+
":poisitionId, :emailAdd, :startDate, :endDate, :genderId, " +
":phoneNo, :dob)";
logger.debug("Executing saveOfficer String " + sql);
int count = getJdbcTemplate().update(sql,new MapSqlParameterSource()
.addValue("userName",officer.getUserName())
.addValue("password", officer.getPassword())
.addValue("fName", officer.getfName())
.addValue("lName", officer.getlName())
.addValue("oName", officer.getoName())
.addValue("divisionNo", officer.getDivisionNo())
.addValue("positionId",officer.getPositionId())
.addValue("emailAdd", officer.getEmailAdd())
.addValue("startDate", officer.getStartDate())
.addValue("endDate", officer.getEndDate())
.addValue("genderId", officer.getGenderId())
.addValue("phoneNo",officer.getPhoneNo())
.addValue("dob", officer.getDob()));
logger.info(count +" Rows affected in tblOfficers");
}catch(Exception e){
logger.info(e.getMessage());
}
}
Officers.java
/** * */
import java.util.Date;
public class Officers {
private String userName;
private String password;
private String password2;
private String fName;
private String lName;
private String oName;
private int divisionNo;
private int positionId;
private String emailAdd;
private Date startDate;
private Date endDate;
private String genderId;
private String phoneNo;
private Date dob;
/**
* No args constructor
*/
public Officers() {
}
/**
* @param userName
* @param password
* @param fName
* @param lName
* @param oName
* @param divisionNo
* @param positionId
* @param emailAdd
* @param startDate
* @param endDate
* @param genderId
* @param phoneNo
* @param dob
*/
public Officers(String userName, String password, String fName, String lName,
String oName, int divisionNo, int positionId, String emailAdd,
Date startDate, Date endDate, String genderId, String phoneNo,
Date dob) {
this.userName = userName;
this.password = password;
this.fName = fName;
this.lName = lName;
this.oName = oName;
this.divisionNo = divisionNo;
this.positionId = positionId;
this.emailAdd = emailAdd;
this.startDate = startDate;
this.endDate = endDate;
this.genderId = genderId;
this.phoneNo = phoneNo;
this.dob = dob;
}
/**
* @return the BadgeNo
*/
public String getUserName() {
return userName;
}
/**
* @param badgeNo the BadgeNo to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return the Password
*/
public String getPassword() {
return password;
}
/**
* @param password the Password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the First Name
*/
public String getfName() {
return fName;
}
/**
* @param fName the First Name to set
*/
public void setfName(String fName) {
this.fName = fName;
}
/**
* @return the Last Name
*/
public String getlName() {
return lName;
}
/**
* @param lName the Last Name to set
*/
public void setlName(String lName) {
this.lName = lName;
}
/**
* @return the Other Name
*/
public String getoName() {
return oName;
}
/**
* @param oName the Other Name to set
*/
public void setoName(String oName) {
this.oName = oName;
}
/**
* @return the DivisionNo
*/
public int getDivisionNo() {
return divisionNo;
}
/**
* @param divisionNo the DivisionNo to set
*/
public void setDivisionNo(int divisionNo) {
this.divisionNo = divisionNo;
}
/**
* @return the PositionId
*/
public int getPositionId() {
return positionId;
}
/**
* @param positionId the PositionId to set
*/
public void setPositionId(int positionId) {
this.positionId = positionId;
}
/**
* @return the Email Address
*/
public String getEmailAdd() {
return emailAdd;
}
/**
* @param emailAdd the Email Address to set
*/
public void setEmailAdd(String emailAdd) {
this.emailAdd = emailAdd;
}
/**
* @return the Start Date
*/
public Date getStartDate() {
return startDate;
}
/**
* @param startDate the Start Date to set
*/
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
/**
* @return the End Date
*/
public Date getEndDate() {
return endDate;
}
/**
* @param endDate the End Date to set
*/
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
/**
* @return the GenderId
*/
public String getGenderId() {
return genderId;
}
/**
* @param genderId the GenderId to set
*/
public void setGenderId(String genderId) {
this.genderId = genderId;
}
/**
* @return the Phone Number
*/
public String getPhoneNo() {
return phoneNo;
}
/**
* @param phoneNo the Phone Number to set
*/
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
/**
* @return the Date Of Birth
*/
public Date getDob() {
return dob;
}
/**
* @param dob the Date Of Birth to set
*/
public void setDob(Date dob) {
this.dob = dob;
}
/**
* @return the password2
*/
public String getPassword2() {
return password2;
}
/**
* @param password2 the password2 to set
*/
public void setPassword2(String password2) {
this.password2 = password2;
}
}
更新错误日志
57818 [http-8084-3] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
57820 [http-8084-3] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
57820 [http-8084-3] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - Database product name cached for DataSource [org.apache.commons.dbcp.BasicDataSource@1077e76]: name is 'MySQL'
57824 [http-8084-3] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - SQL error codes for 'MySQL' found
57825 [http-8084-3] DEBUG org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with Error code '0', will now try the fallback translator
57825 [http-8084-3] DEBUG org.springframework.jdbc.support.SQLStateSQLExceptionTranslator - Extracted SQL state class 'S1' from value 'S1009'
57825 [http-8084-3] ERROR com.crimetrack.jdbc.JdbcOfficersDAO - Could not save officer
org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [INSERT INTO crimetrack.tblofficers (userName,password, fName, lName, oName, divisionNo, poisitionId, emailAdd, startDate, endDate, genderId, phoneNo, dob) VALUES (:userName,:password, :fName, :lName, :oName, :divisionNo, :poisitionId, :emailAdd, :startDate, :endDate, :genderId, :phoneNo, :dob)]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:812)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:868)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:876)
at com.crimetrack.jdbc.JdbcOfficersDAO.saveOfficer(JdbcOfficersDAO.java:113)
at com.crimetrack.service.OfficerManager.RegisterOfficer(OfficerManager.java:21)
at com.crimetrack.web.OfficerRegistrationController.handleRequest(OfficerRegistrationController.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.PreparedStatement.setSerializableObject(PreparedStatement.java:3359)
at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3010)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:229)
at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:351)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:216)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:144)
at org.springframework.jdbc.core.ArgPreparedStatementSetter.doSetValue(ArgPreparedStatementSetter.java:65)
at org.springframework.jdbc.core.ArgPreparedStatementSetter.setValues(ArgPreparedStatementSetter.java:46)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:816)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587)
... 34 more
57826 [http-8084-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Method [handleRequest] returned [ModelAndView: reference to view with name 'officer_registration'; model is null]
57827 [http-8084-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'officer_registration'; URL [/WEB-INF/jsp/officer_registration.jsp]] in DispatcherServlet with name 'crimetrack'
最佳答案
您使用的是 JdbcTemplate(而不是已弃用的 SimpleJdbcTemplate)还是 NamedParameterJdbcTemplate?
只有 SimpleJdbcTemplate 和 NamedParameterJdbcTemplate 支持命名参数。
关于java - Spring - 无效参数值 : java. io.NotSerializableException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12733713/
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在使用Ruby2.1.1和Rails4.1.0.rc1。当执行railsc时,它被锁定了。使用Ctrl-C停止,我得到以下错误日志:~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`gets':Interruptfrom~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`verify_server_version'from~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.
两者都可以defsetup(options={})options.reverse_merge:size=>25,:velocity=>10end和defsetup(options={}){:size=>25,:velocity=>10}.merge(options)end在方法的参数中分配默认值。问题是:哪个更好?您更愿意使用哪一个?在性能、代码可读性或其他方面有什么不同吗?编辑:我无意中添加了bang(!)...并不是要询问nobang方法与bang方法之间的区别 最佳答案 我倾向于使用reverse_merge方法:option
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa