Skip to content

Instantly share code, notes, and snippets.

@timoteoponce
Created May 20, 2015 13:38
Show Gist options
  • Save timoteoponce/e1dee65469c718d1634c to your computer and use it in GitHub Desktop.
Save timoteoponce/e1dee65469c718d1634c to your computer and use it in GitHub Desktop.
GetConnectionJEE
@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