theTuxRacer
theTuxRacer

Reputation: 13869

Do I need to manage DB connection pools in Play Framework, or does Play do it for me?

Do I need to obtain a context and DataSource in every method that reads/writes to the DB? (Sample below) Or does Play.db.DB's getConnection() method handle the pool transparently?

    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();
    }
}

Upvotes: 3

Views: 2648

Answers (1)

liponcio
liponcio

Reputation: 284

Play can manage that for you.

But why don't you use Play's JPA persistence? http://www.playframework.com/documentation/1.2.5/jpa

That would be even more transparent than getting connections.

Upvotes: 1

Related Questions