반응형
Dto 변수에 set 하는 부분은 기상청 데이터 클래스에서 받아온 데이터를
이런형식으로 정의해주면 된다.
Ex) Dto.setArea_id("set할 데이터");
기상청 API 데이터를 저장하기 위한 dto 클래스
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
public class DBDto {
private String area_id;
private String area_name;
private String ground_temp;
private String cloud_qua;
private String snow_qua;
private String solarrad;
private String sunlight;
private String dew_temp;
private String humidity;
private String wind_dir;
private String wind_spe;
private String rain_qua;
private String temp;
private String time;
public String getArea_id() {
return area_id;
}
public void setArea_id(String area_id) {
this.area_id = area_id;
}
public String getArea_name() {
return area_name;
}
public void setArea_name(String area_name) {
this.area_name = area_name;
}
public String getGround_temp() {
return ground_temp;
}
public void setGround_temp(String ground_temp) {
this.ground_temp = ground_temp;
}
public String getCloud_qua() {
return cloud_qua;
}
public void setCloud_qua(String cloud_qua) {
this.cloud_qua = cloud_qua;
}
public String getSnow_qua() {
return snow_qua;
}
public void setSnow_qua(String snow_qua) {
this.snow_qua = snow_qua;
}
public String getSolarrad() {
return solarrad;
}
public void setSolarrad(String solarrad) {
this.solarrad = solarrad;
}
public String getSunlight() {
return sunlight;
}
public void setSunlight(String sunlight) {
this.sunlight = sunlight;
}
public String getDew_temp() {
return dew_temp;
}
public void setDew_temp(String dew_temp) {
this.dew_temp = dew_temp;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public String getWind_dir() {
return wind_dir;
}
public void setWind_dir(String wind_dir) {
this.wind_dir = wind_dir;
}
public String getWind_spe() {
return wind_spe;
}
public void setWind_spe(String wind_spe) {
this.wind_spe = wind_spe;
}
public String getRain_qua() {
return rain_qua;
}
public void setRain_qua(String rain_qua) {
this.rain_qua = rain_qua;
}
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
기상청 API 데이터를 저장하는 dto 클래스의 데이터를 가져와서 db에 데이터를 삽입하는 클래스
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
60
61
62
63
|
class DBConnection {
public int DBInsert(DBDto dto)
{
int iret = 0;
PreparedStatement pstmt = null;
Connection conn = null;
try {
String user = "dbuser";
String pw = "dbpw";
conn = DriverManager.getConnection(url, user, pw);
String sql = "insert into 테이블 명 values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, dto.getArea_id());
pstmt.setString(2, dto.getArea_name());
pstmt.setString(3, dto.getGround_temp());
pstmt.setString(4, dto.getCloud_qua());
pstmt.setString(5, "0");
pstmt.setString(6, dto.getSolarrad());
pstmt.setString(7, dto.getSunlight());
pstmt.setString(8, dto.getDew_temp());
pstmt.setString(9, dto.getHumidity());
pstmt.setString(10, dto.getWind_dir());
pstmt.setString(11, dto.getWind_spe());
pstmt.setString(12, "0");
pstmt.setString(13, dto.getTemp());
pstmt.setString(14, dto.getTime());
pstmt.executeUpdate();
/*pstmt.setString(1, WeatherData);*/
}catch(Exception e) {
System.out.println(e.getMessage());
System.out.println("===============================DB연결실패===============================");
}
return iret;
}
}
public class WeatherDB {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
반응형
'JAVA' 카테고리의 다른 글
자바 Timer 클래스를 사용하여 일정시간에 주기적인 작업하기 (1) | 2019.06.19 |
---|---|
자바 JAR 파일 배포하기 (실행에러포함) (1) | 2019.06.19 |
[기상청 API] 종관기상관측 사용하기 (0) | 2019.06.14 |
[기상청 API] 동네예보정보조회 사용하기 (0) | 2019.06.13 |
Model1 간략한 로그인 기능 만들기 - 회원정보보기(list) (0) | 2019.05.28 |