我是否需要在每个读取/写入数据库的方法中获取上下文和数据源?(下面的示例)或者Play.db.DB
getConnection() 方法是否透明地处理池?
public void saveResponse() {
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx
.lookup("java:comp/env/jdbc/MySQLDB");
conn = ds.getConnection();
stmt = conn.createStatement();
stmt.execute("SOME SQL QUERY");
stmt.close();
stmt = null;
conn.close();
conn = null;
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}