2012-10-04 14 views
7

मैं एक तालिका में एक रिकॉर्ड डालने का प्रयास कर रहा हूं और मुझे निम्न त्रुटि मिल रही है: मैंने "?" का उपयोग करने का भी प्रयास किया एसक्यूएल कथन में पैरामीटर के लिए और एक ही त्रुटि मिली।वसंत - अमान्य तर्क मान: java.io.NotSerializableException

त्रुटि

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 [[email protected]] 
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 [[email protected]]: 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 [[email protected]]: 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' 
+0

अपडेट – devdar

+0

बनाया गया था जब आप कहते हैं कि अधिकारियों की परिभाषा का मतलब xml परिभाषा है? यदि हां, तो मेरे पास अधिकारियों के लिए xml परिभाषा नहीं है, मुझे इसे बनाने की आवश्यकता होगी, यह – devdar

+0

जैसा दिखता है, शायद http://stackoverflow.com/questions/20424989/jdbctemplate-in-search-not-working-properly – Gray

उत्तर

1

यह था दो बातें का एक संयोजन, जिनकी सहायता से इस समस्या का समाधान:

public void saveOfficer(Officers officer) { 
     logger.info("In saveOfficer"); 

     int count = getJdbcTemplate().update("INSERT INTO crimetrack.tblofficers (userName,password, fName, lName, oName, divisionNo, positionId, emailAdd, startDate, endDate, genderId,phoneNo, dob,badgeNo) "+ 
               "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)" 
               , new Object[]{officer.getUserName(),StringSecurity.EncryptString(officer.getPassword()),officer.getfName(), 
               officer.getlName(),officer.getoName(),officer.getDivisionNo(),officer.getPositionId(), 
               officer.getEmailAdd(),officer.getStartDate(),officer.getEndDate(),officer.getGenderId(), 
               officer.getPhoneNo(),officer.getDob(),officer.getBadgeNo()}); 

     logger.info(count +" Rows affected in tblOfficers");    

    } 

और वर्ग मैं @Visher के रूप में शामिल पर दर्शाया

public class Officers implements Serializable{ 
1

एक तरफ हर अपवाद है कि अपने कोड ब्लॉक में हो सकता है को पकड़ने से आप सिर्फ इतना है कि फेंक दिया जाता है और इसलिए आप स्टैकट्रेस खो रहे हैं अपवाद का संदेश बाहर प्रिंट कर रहे हैं जो आपको अपने अपवाद की उत्पत्ति की ओर ले जाता है।

वसंत बस RuntimeException(s) फेंकता है क्योंकि आप अपने अपवाद हैंडलिंग को हटा सकते हैं और स्टैकट्रैक को देख सकते हैं जो आपको ऑब्जेक्ट के बारे में और अधिक बताएगा जो क्रमिक नहीं है। एक विकल्प के रूप में आप कथन को logger.error("Could not save officer.", e); द्वारा अपने अपवाद हैंडलिंग के अंदर प्रतिस्थापित कर सकते हैं, यह मानते हुए कि आप log4j का उपयोग कर रहे हैं। यह आपको रैपिंग अपवाद के संदेश की तुलना में त्रुटि के बारे में और बताएगा।

अपने कोड को देखकर एक उम्मीदवार जो इस अपवाद का कारण बन रहा है Officers कक्षा हो सकता है। क्या आप इसे सत्र में स्टोर करने की कोशिश कर रहे हैं?

+0

से संबंधित नया त्रुटि लॉग – devdar

+0

पोस्ट नहीं किया गया है, मैं सत्र – devdar

2

अधिकारी कक्षा में Serializable लागू करने का प्रयास करें। इसमें सबकुछ अभी क्रमबद्ध है, और यदि वह वर्ग है जो इस मुद्दे का कारण बन रहा है, तो यह ठीक हो जाएगा।

ओपी की मदद नहीं करने के बाद प्रतिक्रिया में जोड़ना, लेकिन आम तौर पर एक धारावाहिक अपवाद नहीं होता है क्योंकि ऑब्जेक्ट को Serializable के रूप में चिह्नित नहीं किया जाता है।

बस उस कोड में देखा गया है कि आपका वर्ग 'poisitionId' का उपयोग कर रहा है लेकिन आपका ऐडवैल्यू 'positionId' का उपयोग कर रहा है। शायद यह विसंगति आपकी समस्या का कारण बन रही है?

+0

में इसे स्टोर करने की कोशिश नहीं कर रहा हूं, मुझे समस्या को हल करने के लिए एक और प्रयास के साथ अद्यतन त्रुटि – devdar

+0

मिल रही है। – Mikezx6r

+1

वास्तव में समस्या फ़ील्ड नाम की वर्तनी नहीं थी क्योंकि डेटाबेस में एक ही वर्तनी थी। मैंने getJdbcTemplate() अद्यतन किया है ("डालें ... मान ... (?,?,? ...), नई वस्तु [] {officer.getUserName}" जैसे और यह मेरे लिए काम करता था। इसलिए समस्या थी स्टेटमेंट स्वयं। त्रुटि को इंगित करने के लिए धन्यवाद क्योंकि मैंने इसे ठीक किया है। – devdar

0
public class Officers implements Serializable { 
+0

यदि आप बताते हैं कि आपका उत्तर उनकी समस्या का समाधान क्यों करेगा, तो यह ओपी की मदद कर सकता है – RobV

+0

यह त्रुटि लॉग नहीं किया गया – devdar

14

आप JdbcTemplate (SimpleJdbcTemplate के बजाय जिसका बहिष्कार किया जाता है) या NamedParameterJdbcTemplate का उपयोग कर रहे हैं?

नामित पैरामीटर केवल SimpleJdbcTemplate और NamedParameterJdbcTemplate में समर्थित हैं।

2

हाय मुझे आपके साथ एक ही समस्या थी।

मैं वर्तमान में वसंत 3.2 का उपयोग कर रहा हूं और ऐसा लगता है कि इस संस्करण में आपको जेडीबीसी टेम्पलेट की जगह नामांकित पैरामीटर जेडीबीसी टेम्पलेट का उपयोग करना होगा। ऐसा करने से यह मेरी समस्या का समाधान करता है।

यदि आप जेडीबीसीडाओस्पोर्ट से विस्तार कर रहे हैं, तो इसके बजाय नामांकित पैरामीटर जेडीबीसीडाओ समर्थन का उपयोग करें।इस वर्ग में आप दोनों एक jdbcTemplate और एक NamedParameterJdbcTemplate

+0

नामांकित पैरामीटर जेडीबीसी टेम्पलेट JdbcTemplate के बजाय क्यों काम करता है? कृपया अधिक जानकारी के साथ अपना उत्तर अपडेट करें। – adamdunson

संबंधित मुद्दे