Skip to main content

Help with resource injection

1 reply [Last post]
mperemsky
Offline
Joined: 2005-01-10
Points: 0

I have been forced to switch from Tomcat to Glassfish to test web services. During this move I have found that the way datasources in Tomcat are made are not the same as in Glassfish. I have read that resource injection is a good way to separate the code from the data source, but have not found anything that identifies all the steps involved. I have attempted to create a connection to the datasource using the @Resource annotation, but it did not work. I then started the Glassfish admin module and created a connection pool (named supportPool - it is pingable) and a JDBC Resource named supportdb that uses the supportPool.

I am on a short deadline and have been trying for hours to get this working. I am using NetBeans to create web services and the web service client. An help would be greatly appreciated.

public class MyClass {

private @Resource(name="supportdb") javax.sql.DataSource supportDS;

public void foo() {

// At this point supportDS is null, from what I've read this should contain a connection to the data source

Connection conn = supportDS.getConnection();

}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mperemsky
Offline
Joined: 2005-01-10
Points: 0

Sorry for the spam. Internet connection is slow tonight, refreshing the browser re-posted.