Skip to main content

getting datasource to work

No replies
yakridge
Offline
Joined: 2011-07-09
Points: 0

I have used data sources with JBoss and OpenEJB successfully. I want to establish a datasource that works with Glassfish.

I'm using Postgresql 9.2, Netbeans7.4 and JDK1.7u40 on 64 bit linux.

I use the admin console to define a datasource. The driver jar is in the domain1/lib directory. The driver class is PGSimpleDataSource. I complete the properties for server, port. user, password, etc. and the datasource appears to be created. Ping works as expected. I then create a resource by name: myResource based upon the datasource.

I then have the following statements in my EJB:

@Resource(name="myResource") private javax.sql.DataSource datasource;
// datasource is an instance of: com.sun.gjc.spi.jdbc40.DataSource40
// this is the only place I can think I might be going wrong but I haven't found anything documenting any other format for injecting the datasource

Connection connection = datasource.getConnection();
// connection is an instance of: com.sun.gjc.spi.jdbc40.ConnectionWrapper40

Statement statement = connection.createStatement();
// statemente is an instance of: com.sun.gjc.spi.jdbc40.StatementWrapper40

ResultSet rs = statement.execute("SELECT * FROM JPL.TICKERS");
// throws exception that the schema does not exist.

Question: should any of the classes returned be Postgresql classes or is it correct to always return wrapped instances?
I have read all the docs I can find from the JEE7 tutorial to all the pertinent Glassfish documentation.

Does anybody see what I am doing wrong?