๋ฐ์ํ
๋ฐ์์จ ๋ฐ์ดํฐ db์ ์ธ์ํธ ํ๋ ๋ถ๋ถ!!
//ํ๋ก์ ํธ ํต์ผ๋ก ์ฌ๋ ค๋ ๊นํ๋ธ ์ฃผ์์ ๋๋ค.
๋ค๋ฅธ ๋ด์ฉ์ด ๊ถ๊ธํ์๋ค๋ฉด ํ์ธ ํด ์ฃผ์ธ์.
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;
int res = 0;
con = getConnection();
String query = "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");
}
} 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 ๋
}
}
๋ ์์ธํ ๋ด์ฉ์ด๋ ์ถ๊ฐ ์ฝ๋๊ฐ ๊ถ๊ธํ๋ค๋ฉด ์ ๊นํ๋ธ๋ฅผ ํ์ธํด์ฃผ์ธ์๐ฉ๐ซ๐งก
๋ฐ์ํ
๋๊ธ