I am developing a JavaEE environment (weblogic 12), and part of my code uses JDBC; Therefore, I need to connect to the JDBC connection from the application server.
I know that it is very bad practice to use JDBC in JavaEE, but the code that I cannot change (legacy).
I found a way to do this, but I'm not sure if this is the right way:
@Resource(mappedName="mydsjndipath") private DataSource ds; public void foo() { Connection conn = ds.getConnection(); }
The question is, what should I do with the connection at the end?
I cannot really execute / rollback because I am using a distributed transaction. But should I at least close it?
And will the JTA transaction always work with the connection (when committing / rolling back)?
Or maybe there is another better way to use JDBC in JavaEE? (no, internal EntityManager requests will not be executed)
source share