package org.wildfly.swarm.examples.ds.deployment;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

/**
 * @author Bob McWhirter
 */
@Path("/")
public class MyResource {

    @GET
    @Produces("text/plain")
    public String get() throws NamingException, SQLException {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("jboss/datasources/ExampleDS");
        Connection conn = ds.getConnection();
        try {
            return "Howdy using connection: " + conn;
        } finally {
            conn.close();
        }
    }
}

@@ -616,16 +616,21 @@
         
+try (
 Connecti
@@ -657,29 +657,17 @@
 ection()
-;%0A        try
+)
  %7B%0A     
@@ -719,54 +719,8 @@
 nn;%0A
-        %7D finally %7B%0A            conn.close();%0A
     

use try-with-resource (#92)