summaryrefslogtreecommitdiff
path: root/src/main/java/cn/ac/iie/utils/dao/ClickHouseUtils.java
blob: 3dced6d0faeda7f0e8a8ffda67597de02d30ceea (plain)
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
package cn.ac.iie.utils.dao;


import com.zdjizhi.utils.StringUtil;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;

/**
 * ClickHouse 入库类型转换类
 *
 * @author Administrator
 */
public class ClickHouseUtils {

    public static void setInt(PreparedStatement pstms, int index, String str) {
        try {
            int num = 0;
            if (str != null) {
                num = Integer.parseInt(str);
            }
            pstms.setInt(index, num);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void setString(PreparedStatement pstmts, int index, String str) throws Exception {
        if (StringUtil.isNotBlank(str)) {
            pstmts.setString(index, str);
        } else {
            str = "";
            pstmts.setString(index, str);
        }
    }

    public static void setTimeStamp(PreparedStatement pstmts, int index, String str) throws Exception {
        pstmts.setTimestamp(index, new Timestamp(Long.parseLong(str + "000")));
    }

    public static void setLong(PreparedStatement pstmts, int index, String str) throws Exception {
        pstmts.setLong(index, Long.parseLong(str));
    }


}