๋ฐ์ํ
๊ธฐ์์ฒญ api๋ 3์๊ฐ ๊ฐ๊ฒฉ์ผ๋ก ๋ ์จ์ ๋ณด๊ฐ ์ ์ฅ๋์ด ์์ด์.
๊ทธ๊ฑฐ๋ฅผ 1์๊ฐ ๊ฐ๊ฒฉ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ์ ์๋๋ก ์ง๋ณธ ์ฝ๋์ ๋๋ค.
//ํ๋ก์ ํธ ํต์ผ๋ก ์ฌ๋ ค๋ ๊นํ๋ธ ์ฃผ์์ ๋๋ค.
๋ค๋ฅธ ๋ด์ฉ์ด ๊ถ๊ธํ์๋ค๋ฉด ํ์ธ ํด ์ฃผ์ธ์.
github.com/Joowon0220/weather.git
package com.weather03.mvc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static com.weather03.db.JDBCTemplate.*;
public class VillageWeatherDAO {
public int insertVillageWeather(List<VillageWeather> vw) throws ClassNotFoundException {
Connection con = null;
ResultSet rs = null;
PreparedStatement insert_pstm = null;
PreparedStatement insert_pstm2 = null;
PreparedStatement insert_pstm3 = null;
int res = 0;
con = getConnection();
String query = "INSERT INTO WEATHER03" + " VALUES(getdate(),?,?,?,?)";
String query2 = "INSERT INTO WEATHER03" + " VALUES(getdate(),?,?,?,?)";
String query3 = "INSERT INTO WEATHER03" + " VALUES(getdate(),?,?,?,?)";
try {
for (int i = 0; i < vw.size(); i++) {
VillageWeather str = vw.get(i);
insert_pstm = con.prepareStatement(query);
insert_pstm.setString(1, str.getBaseDate());
insert_pstm.setString(2, str.getBaseTime());
insert_pstm.setString(3, str.getT3h());
insert_pstm.setString(4, str.getReh());
System.out.println("3.query ready");
res = insert_pstm.executeUpdate();
if (res > 0) {
commit(con);
System.out.println("์ธ์ํธ ์ฑ๊ณต");
}
System.out.println("4.return");
}
for (int i = 0; i < vw.size(); i++) {
VillageWeather str = vw.get(i);
int baseTime2 = Integer.parseInt(str.getBaseTime())+100;
String new_baseTime2 = String.format("%04d", baseTime2);
insert_pstm2 = con.prepareStatement(query2);
insert_pstm2.setString(1, str.getBaseDate());
insert_pstm2.setString(2, new_baseTime2);
insert_pstm2.setString(3, str.getT3h());
insert_pstm2.setString(4, str.getReh());
System.out.println("3.query ready");
res = insert_pstm2.executeUpdate();
if (res > 0) {
commit(con);
System.out.println("์ธ์ํธ ์ฑ๊ณต");
}
System.out.println("4.return");
}
for (int i = 0; i < vw.size(); i++) {
VillageWeather str = vw.get(i);
int baseTime3 = Integer.parseInt(str.getBaseTime())+200;
String new_baseTime3 = String.format("%04d", baseTime3);
insert_pstm3 = con.prepareStatement(query3);
insert_pstm3.setString(1, str.getBaseDate());
insert_pstm3.setString(2, new_baseTime3);
insert_pstm3.setString(3, str.getT3h());
insert_pstm3.setString(4, str.getReh());
System.out.println("3.query ready");
res = insert_pstm3.executeUpdate();
if (res > 0) {
commit(con);
System.out.println("์ธ์ํธ ์ฑ๊ณต");
}
System.out.println("4.return");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("3 or 4 error");
e.printStackTrace();
} finally {
close(insert_pstm, con);
}
return res;
// else ๋
}
}
๋ฐ์ํ
'l ๐ค ์ฝ๋ l' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๊ธฐ์์ฒญ ๋ ์จ api ๋ฐ์์์ db์ ์ ์ฅํ๊ธฐ (sql) (0) | 2020.05.21 |
---|---|
๊ธฐ์์ฒญ ๋ ์จ api ๋ฐ์์์ db์ ์ ์ฅํ๊ธฐ (DTO) (0) | 2020.05.21 |
๊ธฐ์์ฒญ ๋ ์จ api ๋ฐ์์์ db์ ์ ์ฅํ๊ธฐ (DAO) (0) | 2020.05.21 |
๊ธฐ์์ฒญ ๋ ์จ api ๋ฐ์์์ db์ ์ ์ฅํ๊ธฐ (JDBC Template) (0) | 2020.05.21 |
๋ฆฌ์กํธ ํด๋์ค๋ช ์์ด css ์คํ์ผ๋งํ๊ธฐ (0) | 2020.04.10 |
๋๊ธ