users@glassfish.java.net

Re: Programmatic Access to GF JDBC resource

From: <glassfish_at_javadesktop.org>
Date: Thu, 08 Oct 2009 23:45:21 PDT

Could you post your DataSource definition and lookup code?
Do you have to access the DS from a client or from a session bean?

It should work like this:

1. Have a "JDBC Resource" configured in Glassfish with JNDI Name=JNDI Name:
"jdbc/SomeDataSource"

(2. Client-Classpath:
GF v3: Have glassfish\modules\gf-client.jar in your classpath
GF v2: Have glassfish\lib\appserv-rt.jar in your classpath (not sure about that one)
)

3. Lookup:
InitialContext ic = new InitialContext();
DataSource dataSource = (DataSource)ic.lookup("jdbc/SomeDataSource");
Connection jdbcConnection = dataSource.getConnection();

-Matthias
[Message sent by forum member 'matthiasfraass' (matthias.fraass_at_tricoder.net)]

http://forums.java.net/jive/thread.jspa?messageID=367374