为什么更新的字段不是UPDATE请求的一部分?

时间:2013-12-20 07:13:43

标签: java mysql hibernate jsp struts

我正在使用StrutsJSP创建一个表,用户可以在表中更新记录。

更新查询UpdateExchangeRate.xml是:

<query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="callType.xsd">
  <statement>
     update EXCHANGE_RATES set Code = ?, RATE = ?, DATE_UPDATED = ? where START_DT = ? and END_DATE = ?
  </statement>
   <parms>
      <parm datatype="VARCHAR" type="IN"/>
      <parm datatype="DECIMAL" type="IN"/>      
      <parm datatype="DATE" type="IN"/>
      <parm datatype="DATE" type="IN"/>
      <parm datatype="DATE" type="IN"/>
   </parms>
   <datasource>mysql</datasource>
</query>

exchange_rates.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="page.xsd">
<columns>
    <group id="exchange_rates">
        <column name="START_DT" displayName="Start Date"/>
        <column name="END_DATE" displayName="End Date"/>
        <column name="Code" displayName="Code"/>
        <column name="RATE" displayName="Rate"  />
        <column name="DATE_UPDATED" displayName="Date Updated"  />
    </group>
</columns>
<javascript>yenToDollarExchangeRate.js</javascript>
<daoConfig>
    <operations>
        <operation type="RETRIEVE">
            <dao name="exchange_rates/GetExchangeRate" id="exchangeRate" groupId="exchange_rates" display="table" />
        </operation>
      <operation type="UPDATE">
            <dao name="exchange_rates/UpdateExchangeRate" id="exchangeRate" >
                <param requestParameter="Code" />
                <param requestParameter="RATE" />
                <param requestParameter="DATE_UPDATED"  />
                <param requestParameter="START_DT" />
                <param requestParameter="END_DATE" />
            </dao>
        </operation>
    </operations>
  </daoConfig>
 </page>

执行更新查询时,一切正常,但START_DT更新为当前日期。

我不知道为什么会发生这种情况,因为我甚至没有在更新查询中更新START_DT。

这是日志:

SystemOut,014 [SampleApp] com.app.common.util.DAOFrameworkUtil [DEBUG] - Interpretation of file /xml/dao/exchange_rates/UpdateExchangeRate.xml as Procedure was unsuccessful. Retrying as Query.
SystemOut,022 [SampleApp] com.app.common.dao.GenDAO [INFO ] - callString = 
    update EXCHANGE_RATES set Code = ?, RATE = ?, DATE_UPDATED = ? where START_DT = ? and END_DATE = ?

SystemOut,023 [SampleApp] com.app.common.dao.GenDAO [DEBUG] - parmValues = 
SystemOut,023 [SampleApp] com.app.common.dao.GenDAO [DEBUG] - p value = C
SystemOut,023 [SampleApp] com.app.common.dao.GenDAO [DEBUG] - p value = 870.000
SystemOut,024 [SampleApp] com.app.common.dao.GenDAO [DEBUG] - p value = 2013-09-17
SystemOut,024 [SampleApp] com.app.common.dao.GenDAO [DEBUG] - p value = 2010-08-01 <<---- This is the value that UI should show instead of current date
SystemOut,024 [SampleApp] com.app.common.dao.GenDAO [DEBUG] - p value = 2010-08-31
SystemOut,024 [SampleApp] com.app.common.dao.GenDAO [INFO ] - parmL .size() = 5, parmValues.length = 5
SystemOut,025 [SampleApp] com.app.common.dao.GenDAO [INFO ] - parm.getType() = IN, parm.getDatatype() = VARCHAR
SystemOut,025 [SampleApp] com.app.common.dao.GenDAO [INFO ] - method name = setString
SystemOut,025 [SampleApp] com.app.common.dao.GenDAO [INFO ] - parm.getType() = IN, parm.getDatatype() = DECIMAL
SystemOut,025 [SampleApp] com.app.common.dao.GenDAO [INFO ] - method name = setBigDecimal
SystemOut,026 [SampleApp] com.app.common.dao.GenDAO [INFO ] - parm.getType() = IN, parm.getDatatype() = DATE
SystemOut,026 [SampleApp] com.app.common.dao.GenDAO [INFO ] - method name = setDate
SystemOut,026 [SampleApp] com.app.common.dao.GenDAO [INFO ] - parm.getType() = IN, parm.getDatatype() = DATE
SystemOut,026 [SampleApp] com.app.common.dao.GenDAO [INFO ] - method name = setDate
SystemOut,027 [SampleApp] com.app.common.dao.GenDAO [INFO ] - parm.getType() = IN, parm.getDatatype() = DATE
SystemOut,027 [SampleApp] com.app.common.dao.GenDAO [INFO ] - method name = setDate
SystemOut,027 [SampleApp] com.app.common.dao.GenDAO [INFO ] - Calling query
SystemOut,114 [SampleApp] com.app.common.dao.GenDAO [INFO ] - Query executed successfully
SystemOut,114 [SampleApp] com.app.common.dao.GenDAO [INFO ] - Calling user defined method to create DTO
SystemOut,114 [SampleApp] com.app.common.dao.GenDAO [INFO ] - Attempting to close resultset, statement and connection
SystemOut,115 [SampleApp] com.app.common.dao.GenDAO [INFO ] - resultset, statement and connection closed successfully

为什么START_DT字段设置为当前日期?

请阅读下面的评论。感谢

1 个答案:

答案 0 :(得分:1)

这样的事情应该这样做:

ALTER TABLE EXCHANGE_RATES
    MODIFY COLUMN START_DT TIMESTAMP NOT NULL;

这个陈述只是一个例子,所以要小心使用它(例如我不知道你的初始列是否可以为空)。

希望这有帮助。