Announcement Announcement Module
Collapse
No announcement yet.
SQLite - not insert float. Unexpected param type: class java.lang.Float Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQLite - not insert float. Unexpected param type: class java.lang.Float

    I have SQLite DB table :
    Code:
    CREATE TABLE callingCard (ID INTEGER NOT NULL PRIMARY KEY, CARD_NB VARCHAR(10) NOT NULL, CARD_VALUE FLOAT NOT NULL, STATUS INTEGER DEFAULT 0);
    CREATE UNIQUE INDEX callingCard_index ON callingCard(CARD_NB);
    domain object:
    Code:
    public class CallingCard {
    	private int id;
    	private String card_nb;
    	private float card_value;
    	private boolean status;
    // getter and setter
    dao:
    Code:
    	@Override
    	public void add(CallingCard callingCard) {
    		logger.info("callingCard=" + callingCard);
    		Map<String, Object> parameters = new HashMap<String, Object>();
    		parameters.put("card_nb", callingCard.getCard_nb());
    		parameters.put("card_value", callingCard.getCard_value());
    		parameters.put("status", Conversion.boolToInt(callingCard.isStatus()));
    		MapSqlParameterSource parameterSourceMapCallingCard = new MapSqlParameterSource(
    				parameters);
    		getSimpleJdbcTemplate().update(CALLINGCARD_INSERT,
    				parameterSourceMapCallingCard);
    	}
    result of log:
    Code:
    Sep 1, 2009 6:47:20 PM com.mycompany.myproject.repository.JdbcCallingCardDao add
    INFO: callingCard=
            ID='0'
            Number='12'
            Value='45.67'
            Status='true'
    throw exception:
    Code:
    Sep 1, 2009 6:47:20 PM com.mycompany.myproject.web.controllers.CallingCardsController add
    SEVERE: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO callingCard (card_nb, card_value, status) VALUES (?, ?, ?
    )]; SQL state [null]; error code [0]; unexpected param type: class java.lang.Float; nested exception is java.sql.SQLException: unexpected pa
    ram type: class java.lang.Float
    org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO callingCard (
    card_nb, card_value, status) VALUES (?, ?, ?)]; SQL state [null]; error code [0]; unexpected param type: class java.lang.Float; nested excep
    tion is java.sql.SQLException: unexpected param type: class java.lang.Float
            at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    
            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:607)
            at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:792)
            at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:815)
            at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:214)
            at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:233)
            at com.mycompany.myproject.repository.JdbcCallingCardDao.add(JdbcCallingCardDao.java:92)
            at com.mycompany.myproject.service.CallingCardManagerImpl.add(CallingCardManagerImpl.java:31)
            at com.mycompany.myproject.web.controllers.CallingCardsController.add(CallingCardsController.java:114)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
            at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
            at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
            at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
            at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
            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:128)
            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:849)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
            at java.lang.Thread.run(Thread.java:619)
    Caused by: java.sql.SQLException: unexpected param type: class java.lang.Float
            at org.sqlite.DB.sqlbind(DB.java:211)
            at org.sqlite.DB.execute(DB.java:258)
            at org.sqlite.DB.executeUpdate(DB.java:281)
            at org.sqlite.PrepStmt.executeUpdate(PrepStmt.java:77)
            at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
            at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:798)
            at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:591)
            ... 33 more
    but if I (for testing) write this:
    Code:
     @Override
    	public void add(CallingCard callingCard) {
    		logger.info("callingCard=" + callingCard);
    		Map<String, Object> parameters = new HashMap<String, Object>();
    		parameters.put("card_nb", callingCard.getCard_nb());
    		parameters.put("card_value", 23.45);
    		parameters.put("status", Conversion.boolToInt(callingCard.isStatus()));
    		MapSqlParameterSource parameterSourceMapCallingCard = new MapSqlParameterSource(
    				parameters);
    		getSimpleJdbcTemplate().update(CALLINGCARD_INSERT,
    				parameterSourceMapCallingCard);
    	}
    then successfully inserted to DB.

  • #2
    I found solution. In the domain object must use Double not float.

    Code:
    public class CallingCard {
    	private int id;
    	private String card_nb;
    	private Double card_value;
    	private boolean status;

    Comment

    Working...
    X