I'm developing in a JavaEE environment (weblogic 12), and part of my code uses JDBC; Therefore, I need to aqcuire a JDBC connection from the application server.
I know it's a really bad practice to use JDBC in JavaEE, but that's a code I cannot change (legacy).
I've found a way to do it, but I'm not sure it's the right way:
@Resource(mappedName="mydsjndipath")
private DataSource ds;
public void foo() {
Connection conn = ds.getConnection();
}
The question is what do I do with the connection at the end?
I can't really commit/rollback it, because I use a distributed transaction. But should I at least close it?
And will the JTA transaction will always effect the connection (on commit/rollback)?
Or maybe there's another better way to use JDBC in JavaEE? (no, the EntityManager's native queries won't do)