¿¹Á¦
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) {
Connection conn = null;
try {
conn = DriverManager.getConnection("url", "user", "password");
// ...
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (conn != null) {
try {
conn.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
}
}
¼Ö·ç¼Ç
javax.sql.DataSource¿¡ getConnection() ¸Þ¼Òµå¸¦ »ç¿ëÇϽʽÿÀ.
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) {
Connection conn = null;
try {
DataSource ds = getDataSource();
conn = ds.getConnection();
// ...
conn.commit();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (conn != null) {
try {
conn.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
}
}

private DataSource getDataSource() {
return _source;
}

private transient DataSource _source;