执行sql查询时出错(spring)

时间:2012-02-09 14:20:39

标签: java sql spring

这是我的GetLastTrade,我想获得另一个方法的int结果 int stockdata count在这里被调用:

public StockData GetLastTrade(String UserName, String SymbolName, StockData stockData)
{
    System.out.println("error in GetLastTrade " + SymbolName + "username==" + UserName + "TRANSDATE ==" + stockData.getTRANSDATE() + "OPENPRICE==" + stockData.getOPENPRICE());

    try
    {
        System.out.println("GetLastTrade done==" + stockData.getTRANSDATE());
        return stockDataService.GetLastTrade(UserName, SymbolName, stockData);
    }
    catch(Exception e)
    {
        System.out.println("stockDataService.GetLastTrade error" +e);
        e.printStackTrace();
    }
    return stockData;
}

这是我的代码中的int countStockData:

public int countStockData(String UserName, String SymbolName, StockData stockData) 
{
    String transdateforquery = stockData.getTRANSDATE();

    try 
    {
       return template.queryForInt(
                        "SELECT COUNT(TRANSDATE) FROM stockdata WHERE transdate= ? AND                        symbolname = ?",
                        rowMapper,transdateforquery, SymbolName);
    } 
    catch (TransientDataAccessResourceException e) 
    {
       System.out.println("TransientDataAccessResourceExc eption====");
       // TODO Auto-generated catch block
       e.printStackTrace();
       return 0;
    }
}

IM收到此错误:

  TransientDataAccessResourceException====
        org.springframework.dao.TransientDataAccessResourc eException: PreparedStatementCallback; SQL [SELECT COUNT(TRANSDATE) FROM stockdata WHERE transdate= ? AND symbolname = ?]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
        at org.springframework.jdbc.support.SQLStateSQLExcept ionTranslator.doTranslate(SQLStateSQLExceptionTran slator.java:107)
        at org.springframework.jdbc.support.AbstractFallbackS QLExceptionTranslator.translate(AbstractFallbackSQ LExceptionTranslator.java:72)
        at org.springframework.jdbc.support.AbstractFallbackS QLExceptionTranslator.translate(AbstractFallbackSQ LExceptionTranslator.java:80)
        at org.springframework.jdbc.support.AbstractFallbackS QLExceptionTranslator.translate(AbstractFallbackSQ LExceptionTranslator.java:80)
        at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:602)
        at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:636)
        at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:665)
        at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:673)
        at org.springframework.jdbc.core.JdbcTemplate.queryFo rObject(JdbcTemplate.java:716)
        at org.springframework.jdbc.core.JdbcTemplate.queryFo rObject(JdbcTemplate.java:727)
        at org.springframework.jdbc.core.JdbcTemplate.queryFo rInt(JdbcTemplate.java:754)
        at org.springframework.jdbc.core.simple.SimpleJdbcTem plate.queryForInt(SimpleJdbcTemplate.java:121)
        at com.ib.client.mts.backend.DAO.StockDataService.cou ntStockData(StockDataService.java:362)
        at com.ib.client.mts.backend.BusinessService.TradingB usinessService.GetStockDataCount(TradingBusinessSe rvice.java:262)
        at com.ib.client.mts.backend.BusinessService.MtsRuleE ngineService.AnalyseRow(MtsRuleEngineService.java: 205)
        at com.ib.client.mts.backend.DAO.UploadDAO.csvinput(U ploadDAO.java:175)
        at com.ib.client.mts.backend.DAO.FileUploadService.do Upload(FileUploadService.java:42)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at flex.messaging.services.remoting.adapters.JavaAdap ter.invoke(JavaAdapter.java:421)
        at flex.messaging.services.RemotingService.serviceMes sage(RemotingService.java:183)
        at flex.messaging.MessageBroker.routeMessageToService (MessageBroker.java:1503)
        at flex.messaging.endpoints.AbstractEndpoint.serviceM essage(AbstractEndpoint.java:884)
        at flex.messaging.endpoints.AbstractEndpoint$$FastCla ssByCGLIB$$1a3ef066.invoke(<generated>)
        at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy. java:191)
        at org.springframework.aop.framework.Cglib2AopProxy$C glibMethodInvocation.invokeJoinpoint(Cglib2AopProx y.java:692)
        at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150)
        at org.springframework.aop.framework.adapter.ThrowsAd viceInterceptor.invoke(ThrowsAdviceInterceptor.jav a:124)
        at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
        at org.springframework.aop.framework.Cglib2AopProxy$F ixedChainStaticTargetInterceptor.intercept(Cglib2A opProxy.java:576)
        at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCG LIB$$3cc0debb.serviceMessage(<generated>)
        at flex.messaging.endpoints.amf.MessageBrokerFilter.i nvoke(MessageBrokerFilter.java:121)
        at flex.messaging.endpoints.amf.LegacyFilter.invoke(L egacyFilter.java:158)
        at flex.messaging.endpoints.amf.SessionFilter.invoke( SessionFilter.java:44)
        at flex.messaging.endpoints.amf.BatchProcessFilter.in voke(BatchProcessFilter.java:67)
        at flex.messaging.endpoints.amf.SerializationFilter.i nvoke(SerializationFilter.java:146)


        at org.springframework.security.ui.SpringSecurityFilt er.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy $VirtualFilterChain.doFilter(FilterChainProxy.java :390)
        at org.springframework.security.util.FilterChainProxy .doFilter(FilterChainProxy.java:175)
        at org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(DelegatingFilterProxy.java:238)
        25more
        org.apache.coyote.http11.Http11AprProtocol$Http11C onnectionHandler.process(Http11AprProtocol.java:56 5)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run( AprEndpoint.java:1509)
        at java.lang.Thread.run(Unknown Source)

上面代码中的问题是什么,以及新代码是什么。我是新手,因此遇到问题

2 个答案:

答案 0 :(得分:0)

我猜你的rowMapper(无论是什么,因为它没有显示)是不可序列化的。我也猜测方法调用不需要它,因为它只在语句中定义了t个变量。

仅供参考:您的命名约定遍及getTRANSDATE(),一些方法名称和变量的上限。你甚至不符合你正在使用的不良做法。

答案 1 :(得分:0)

看起来transdateforquery被定义为字符串。如果数据库列transdate被定义为日期,则这可能不起作用。尝试将transdateforquery转换为java.sql.Date并将其传递给您的查询。