DBUtil.java
public class DButil {
public static Connection getConnection() {
Connection conn = null;
Properties p = new Properties();
try {
p.load(new FileReader(
"src/com/ninethirty/hellolecture/nfc/dbinfo.properties"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String driver = p.getProperty("driver");
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(p.getProperty("url"),
p.getProperty("userid"), p.getProperty("password"));
System.out.println("DB Connection");
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void close(Connection conn, Statement st) {
try {
if (conn != null)
conn.close();
if (st != null)
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
'Computer > JAVA' 카테고리의 다른 글
Java HashMap (0) | 2014.08.13 |
---|---|
Java 16진수로 변환 (0) | 2014.08.12 |
JDBC 출석기능(배열) (0) | 2014.08.11 |
JDBC SQL Select 기본 예제 (0) | 2014.08.11 |
java 배열 선언 (0) | 2014.08.08 |