commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ondrej Tisler (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DBCP-309) First example for FSContext is invalid
Date Wed, 02 Dec 2009 13:06:22 GMT

    [ https://issues.apache.org/jira/browse/DBCP-309?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784807#action_12784807
] 

Ondrej Tisler commented on DBCP-309:
------------------------------------

I use this code for registring JNDI inFSContext:
      // JNDI with datasource
      InitialContext ic = new InitialContext();
      // Construct BasicDataSource reference
      Configuration poolConfig = dbConfig.subset("datasource");
      DriverAdapterCPDS cpds = new DriverAdapterCPDS();
      cpds.setDriver(poolConfig.getString("driver.driverClassName"));
      cpds.setUrl(poolConfig.getString("driver.url"));
      cpds.setUser(poolConfig.getString("driver.username"));
      cpds.setPassword(CryptPass.encryptPass(poolConfig.getString("driver.password")));
      SharedPoolDataSource ds = new SharedPoolDataSource();
      ds.setConnectionPoolDataSource(cpds);
      ds.setDefaultAutoCommit(poolConfig.getBoolean("connection.defaultAutoCommit", true));
      ds.setValidationQuery(poolConfig.getString("validation.validationQuery"));
      ic.rebind(poolConfig.getString("[@jndi]"), ds);
      log.info("JNDI datasource is inicialized");

next you can normaly use JNDI lookup:
      InitialContext ic2 = new InitialContext();
      ds = (DataSource) ic2.lookup(poolConfig.getString("[@jndi]"));
      conn = ds.getConnection();

> First example for FSContext is invalid
> --------------------------------------
>
>                 Key: DBCP-309
>                 URL: https://issues.apache.org/jira/browse/DBCP-309
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.2.2
>            Reporter: Ondrej Tisler
>            Priority: Trivial
>
> First example on page http://commons.apache.org/dbcp/guide/jndi-howto.html is invalid,
with this code every call of  
>   InitialContext ic2 = new InitialContext();
>   DataSource ds = (DataSource) ic2.lookup("jdbc/basic");
>   Connection conn = ds.getConnection();
>   conn.close();
> ends with new datasource with unclosed connection in it becase new Reference("javax.sql.DataSource",
 "org.apache.commons.dbcp.BasicDataSourceFactory", null); reference creates new DataSource
instead using created one while calling  ic2.lookup("jdbc/basic").
> At the end it ends with many opened connections to DB until JVM is ended.
> Second example I didn't test, i use direct aproach with manualy creating SharedPoolDataSource
and registring it in FSContext JNDI itself.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message