That all depends. If you are doing your own JDBC calls then yes you must have some code like that to obtain a connection. If you are using JPA entity beans, however, you do not have to write that code (instead you configure the entity manager to indicate which datasource to use). Or you could use an @Resource annotation to inject the data source.