0

I'm trying to use these methods to access a JDBC Connection Pool on my GlassFish 4 server. However, the method at line 16 doesn't compile, because the parameter is invalid (it will only accept a pair of Strings). Am I missing an Oracle library on the build path or is there a new way of doing this in version 4?

01   private static DataSource dataSource;
02
03   static {
04      try {
05          dataSource = (DataSource) new InitialContext().lookup("jdbc/IconLive");
06      } catch (NamingException e) {
07          throw new ExceptionInInitializerError(e);
08      }
09   }
10
11   public static Connection getConnectionWrapper() throws SQLException {
12       return dataSource.getConnection();
13   }
14
15   public static Connection unwrapConnection(Connection connectionWrapper) throws SQLException {
16       return dataSource.getConnection(connectionWrapper);
17   } 
18
19   public static void releaseConnection(Connection connectionWrapper) throws SQLException {
20       connectionWrapper.close();
21   }
MTCoster
  • 5,868
  • 3
  • 28
  • 49
  • I am not sure why you'd think that would compile. There is no method with the signature `getConnection(java.sql.Connection)` defined on [`DataSource`](http://docs.oracle.com/javase/7/docs/api/javax/sql/DataSource.html). Maybe you are looking for [`Connection.unwrap(...)`](http://docs.oracle.com/javase/7/docs/api/java/sql/Wrapper.html#unwrap(java.lang.Class)) – Mark Rotteveel Feb 11 '14 at 10:40
  • I'm just getting this from an example on the internet. How would I use `Connection.unwrap()`? `Connection` seems to be an interface so is not statically available. – MTCoster Feb 11 '14 at 14:08
  • That I used `Connection.unwrap` did not imply that it was a static method... Every JDBC 4 compliant implementation of `Connection` should have a basic implementation of `unwrap`. – Mark Rotteveel Feb 11 '14 at 14:52
  • I've been working off [this](http://docs.oracle.com/cd/E18930_01/html/821-2418/giyde.html#ggrum) article, which is where I got `getConnection(java.sql.Connection)` from. My question is really what implementation of `Connection` should I be using? – MTCoster Feb 11 '14 at 19:31
  • My first guess would be that you are casting to `javax.sql.DataSource`, otherwise: verify that this method is actually available in GlassFish 4. – Mark Rotteveel Feb 12 '14 at 08:38

0 Answers0