Skip to content

Instantly share code, notes, and snippets.

@gilfernandes
Created May 6, 2014 10:12
Show Gist options
  • Save gilfernandes/b51f59d25aa283b1667f to your computer and use it in GitHub Desktop.
Save gilfernandes/b51f59d25aa283b1667f to your computer and use it in GitHub Desktop.
How to access XA datasource on JBOSS 4 using Groovy
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
Logger log = Logger.getLogger("DisplayTest1")
log.info("Started DisplayTest1")
Context initCtx;
Connection conn = null;
Statement stmt = null;
// How to get the connection from JNDI
initCtx = new InitialContext()
DataSource cvDs = (DataSource) initCtx.lookup("java:/osscube/dev/cv");
try {
conn = cvDs.getConnection();
// How to get the connection string
connStr = conn.getMetaData().getURL();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select count(*) from MLFA1");
while (rs.next()) {
mLFA1Count = rs.getInt(1);
}
rs.close()
}
finally {
stmt.close()
conn.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment