yangys
2025-11-18 8e944cfabb253fc2556588e308e282586043f7b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.qianwen.smartman.common.typehandlers;
 
 
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
 
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
 
@MappedTypes(value = Timestamp.class)
@MappedJdbcTypes(value = {JdbcType.BIGINT,JdbcType.INTEGER})
public class NullableSqlTimestampTypeHandler extends BaseTypeHandler<Timestamp>{
 
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Timestamp parameter, JdbcType jdbcType)
            throws SQLException {
        ps.setTimestamp(i, parameter);
        
    }
 
    @Override
    public Timestamp getNullableResult(ResultSet rs, String columnName) throws SQLException {
        Timestamp val = rs.getTimestamp(columnName);
        if(rs.wasNull()) {
            return null;
        }else {
            return val;
        }
        //return rs.getTimestamp(columnName);
    }
 
    @Override
    public Timestamp getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        Timestamp val = rs.getTimestamp(columnIndex);
        if(rs.wasNull()) {
            return null;
        }else {
            return val;
        }
        //return rs.getTimestamp(columnIndex);
    }
 
    @Override
    public Timestamp getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        Timestamp val = cs.getTimestamp(columnIndex);
        if(cs.wasNull()) {
            return null;
        }else {
            return val;
        }
        //return cs.getTimestamp(columnIndex);
    }
    
}