LoginSignup
0
0

More than 5 years have passed since last update.

Timestamp型のデータを時分秒切り捨てで取得する

Posted at
<resultMap id="javaTypePlus2" class="java.util.HashMap">
    <result column="seirino" property="seirino" />
    <result column="time2" property="time2" jdbcType="Timestamp"
        javaType="java.util.Date" />
    <result column="time1" property="time1" jdbcType="Timestamp"
        javaType="java.sql.Timestamp" />
</resultMap>

<select id="gettime" resultMap="javaTypePlus2" parameterClass="Map">
    SELECT seirino,time1,time2 FROM TIME
</select>

時分秒切り捨てしたい場合
⇒time2の様にjavaTypeにjava.util.Date型を指定する

時分秒も取得したい場合
⇒time1の様に、javaTypeにjava.sql.Timestamp型を指定する

また以下の通り、DBサーバー側の型は問わない(jdbcTypeがTimestamp型でもsqlMap上Date型でも取得可能)

<resultMap id="javaTypePlus2" class="java.util.HashMap">
    <result column="seirino" property="seirino" />
    <result column="time2" property="time2" jdbcType="java.util.Date"
        javaType="java.util.Date" />
    <result column="time1" property="time1" jdbcType="java.util.Date"
        javaType="java.sql.Timestamp" />
</resultMap>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0