Created
May 20, 2015 13:38
-
-
Save timoteoponce/e1dee65469c718d1634c to your computer and use it in GitHub Desktop.
GetConnectionJEE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Stateless @LocalBean | |
public class MyClass{ | |
@Resource(lookup = "java:openejb/Resource/helloDS") | |
private DataSource dataSource; | |
public int countSql(){ | |
Connection conn = datasource.getConnection(); | |
Statement st = null; | |
try{ | |
st = conn.createStatement(); | |
return st.executeQuery("SELECT 0").next().getInt(0); | |
}catch(SQLException e){ | |
}finally{ | |
try{ | |
if(st != null){ | |
st.close(); | |
conn.close(); | |
} | |
}catch(SQLException e){} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment