ํฐ์คํ ๋ฆฌ ๋ทฐ
728x90
SMALL
package util;
import java.sql.*;
import java.io.*;
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");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException 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);
}
}
##############################################################
# db.properties ํ์ผ
##############################################################
#=======================================================
# # is comment
# db setting
#=======================================================
url = jdbc:mysql://localhost:3306/test
user = javamaster
pass = 1111
driver = com.mysql.jdbc.Driver
728x90
LIST
๋๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- asp
- JavaScript
- ์๋ฐ์คํฌ๋ฆฝํธ
- ์ธํจ์ด
- Servlet
- Ajax
- ๋์ค
- JS
- 2ne1
- JSTL
- MySQL
- EL
- ์น์์ด์ ์
- JSON
- ์นด๋ฐ์จ๋ผ์ธ
- ์๋ฆฌ
- JSP
- php
- ์๋ธ๋ฆฟ
- ๋ด๋๋ด์ฐ
- 8๋ง์ผ
- Java
- ๊ฒฝ์ ์ฉ์ด
- I Don't Care
- ์์์ฌ์ด๋
- jQuery
- ๋ฉ๋ฐฐํ
- ํจ์
- ๊ธฐํ
- ๋ณต๊ทผ์ด๋
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
๊ธ ๋ณด๊ดํจ
250x250