ํฐ์คํ ๋ฆฌ ๋ทฐ
package util;
import java.sql.*;
import java.util.*;
public class DBUtil {
private static String driver, url, user, pass;
//๋ณดํต ์ด๋ฐ ์ ๋ณด๋ค์ ํ๋ฒ ์ฝ์ผ๋ฉด ์์ฃผ๋ณ๊ฒฝ๋์ง๋ ์๋๋ค.
//์ด๋ด๊ฒฝ์ฐ ํ๋ฒ ์ฝ์ด์ ๊ณ์ ์ฌํจใ
ใน์ฉ ๋ผํ ์ ์๊ฒ ๋ค.
// ํ๋ฒ ์ฝ์ด์ ์ญ~ ์ด๋ฐ์์
์ด ์๋ค๋ฉด
// static ํค์๋๋ฅผ ๋ ์ฌ๋ฆฌ์.
static {
loadInfo();
driverLoading();
}
private static void loadInfo() {
// TODO Auto-generated method stub
try {
// Properties props;
// File file = new File(System.getProperty("user.dir"), "db.properties");
// FileInputStream fis;
// fis = new FileInputStream("db.properties");
//
// props = new Properties();
// props.load(fis);
//
// url = props.getProperty("url");
// user = props.getProperty("user");
// pass = props.getProperty("pass");
// driver = props.getProperty("driver");
//ํด๋์คpath์ ๋ฃจํธ์์ db.properties๋ฅผ ์ฝ์ด์ค๋ ๋ฐฉ๋ฒ.
ResourceBundle rb = ResourceBundle.getBundle("db");
driver = rb.getString("driver");
url = rb.getString("url");
user = rb.getString("user");
pass = rb.getString("pass");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void driverLoading() {
// TODO Auto-generated method stub
//jdbc 1 driver loading
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, user, pass);
}
public static void close(Connection con, PreparedStatement pstmt, Statement stmt, ResultSet rs) {
//๊ธฐ๋ณธ ๊ธฐ์กฐ๋ ๋์ด ์๋๋ฉด ๋ซ์๋ผ!!!
if (rs !=null)
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (pstmt !=null)
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (stmt !=null)
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (con !=null)
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- Total
- Today
- Yesterday
- ๋ณต๊ทผ์ด๋
- ๋์ค
- JavaScript
- ์ธํจ์ด
- MySQL
- JS
- I Don't Care
- ๊ธฐํ
- ์์์ฌ์ด๋
- ์น์์ด์ ์
- ๋ฉ๋ฐฐํ
- JSON
- ์นด๋ฐ์จ๋ผ์ธ
- 2ne1
- asp
- ์๋ฆฌ
- Ajax
- Servlet
- EL
- php
- ํจ์
- ์๋ธ๋ฆฟ
- JSTL
- ๊ฒฝ์ ์ฉ์ด
- JSP
- ๋ด๋๋ด์ฐ
- jQuery
- ์๋ฐ์คํฌ๋ฆฝํธ
- 8๋ง์ผ
- Java
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |