Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
686 views
in Technique[技术] by (71.8m points)

mysql - Spring - Invalid argument value: java.io.NotSerializableException

I am attempting to insert a record into a table and i am getting the following error: I also tried using "?" for the parameters in the sql statement and got the same error.

Error

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;
    }


}

Updated Error Log

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Are you using JdbcTemplate (instead of SimpleJdbcTemplate which is deprecated) or NamedParameterJdbcTemplate?

Named parameters are only supported in SimpleJdbcTemplate and NamedParameterJdbcTemplate.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...