카테고리 없음2016. 9. 8. 15:10
반응형

spring boot 기반 JdbcTemplate 




1
2
3
4
5
spring.datasource.driver-class-name=com.tmax.tibero.jdbc.TbDriver
spring.datasource.url=jdbc:tibero:thin:@8.8.8.8.:8629:tibero
spring.datasource.username=id
spring.datasource.password=pw
cs






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.example;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.PreparedStatement;
import java.sql.SQLException;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
 
@SpringBootApplication
public class DemoApplication {
    
    private static JdbcTemplate jdbcTemplate;
    private static StringBuffer INSERT_TMP_TBL_MEMBER = new StringBuffer();
    
    public DemoApplication(JdbcTemplate _JdbcTemplate) {
        // TODO Auto-generated constructor stub
        DemoApplication.jdbcTemplate = _JdbcTemplate;
        INSERT_TMP_TBL_MEMBER.append("INSERT INTO TMP_TBL_MEMBER (C_NO,C_BIRTH,C_PHONE,C_PHONE2,C_EMAIL,C_NAME) VALUES(?,?,?,?,?,?)");
    }
    
    public static void main(String[] args) throws IOException{
        SpringApplication.run(DemoApplication.class, args);
        
        Resource resource = new ClassPathResource("TBL_MEMBER.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(),"euc-kr"));
        String tmpStr;
        while ((tmpStr = reader.readLine()) != null) {
            // C_NO,C_BIRTH,C_PHONE,C_PHONE2,C_EMAIL,C_NAME
            String[] params =  tmpStr.split(",");
            if(params.length == 6){
                INSERT_TB_FILE_MANAGE(params);
            }else{
                System.out.println(params.length+":"+params.toString());
            }
        }
    }
    
    private static void INSERT_TB_FILE_MANAGE(String[] params) {
        jdbcTemplate.update(INSERT_TMP_TBL_MEMBER.toString(), new PreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement preparedStatement) throws SQLException {
                // TODO Auto-generated method stub
                preparedStatement.setString(1, params[0== null ? "" : params[0]);
                preparedStatement.setString(2, params[1== null ? "" : params[1]);
                preparedStatement.setString(3, params[2== null ? "" : params[2]);
                preparedStatement.setString(4, params[3== null ? "" : params[3]);
                preparedStatement.setString(5, params[4== null ? "" : params[4]);
                preparedStatement.setString(6, params[5== null ? "" : params[5]);
            }
        });
    }
}
cs


Posted by 1010