org.wildfly.swarm.datasources.test.MyResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testsuite-datasources-config Show documentation
Show all versions of testsuite-datasources-config Show documentation
Test Suite: Datasources via Config
The newest version!
package org.wildfly.swarm.datasources.test;
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();
}
}
}