Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-128

[dbcp] BasicDataSource.getConnection() Connections don't work as hashtable keys -- test case provided



    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.2.1
    • 1.2.2
    • None
    • Operating System: Linux
      Platform: PC

    • 39537


      Code I'm working with uses a Connection as a key in a Hashtable, and while I was
      trying to move from DbConnectionBroker to DBCP, I ran into some problems.

      When retrieving the value from the Hashtable using the Connection originally
      returned by BasicDataSource.getConnection(), I don't get the value back that was
      inserted into the Hashtable. I get null instead.

      I've provided a patch to BasicDataSourceExample.java that can be used as a very
      basic test case. For the purposes of the test, I set up HSQLDB (originally this
      was discovered using JSQLConnect to connect to a MS SQL Server DB), and, using
      the HSQLDB's DatabaseManager, populated a database with the test data (Options
      -> Insert test data).

      The patch to BasicDataSourceExample.java the will get a connection, use it to
      insert a string into a Hashtable, then do some tests that show the problem,
      while still succssfully retrieving data from the database.

      Also in the patch are changes so you can provide all the arguments at the
      command line.

      I tested this with DBCP 1.2.1 with it's dependencies and with the nightly dump
      with the latest releases of commons-collections and commons-pool. For both tests
      the j2ee.jar was version 1.4 and hsqldb.jar was version

      Here's the output from the session with the latest nightly build:
      805: www@animal $-> javac -cp
      806: www@animal $-> java -cp
      BasicDataSourceExample "org.hsqldb.jdbcDriver"
      "jdbc:hsqldb:file:/home/www/hsqldb/test" "sa" "" "SELECT FIRSTNAME, LASTNAME
      Setting up data source.
      Creating connection.
      Hash contains key: jdbc:hsqldb:file:/home/www/hsqldb/test, UserName=SA, HSQL
      Database Engine Driver ? false
      Hash value for key: jdbc:hsqldb:file:/home/www/hsqldb/test, UserName=SA, HSQL
      Database Engine Driver ? null
      Hash contains value: test ? true
      Creating statement.
      Executing statement.
      Laura Steel
      Susanne King
      Anne Miller
      Michael Clancy
      Sylvia Ringer
      Laura Miller
      Laura White
      James Peterson
      Andrew Miller
      James Schneider
      Anne Fuller
      Julia White
      George Ott
      Laura Ringer
      Bill Karsen
      Bill Clancy
      John Fuller
      Laura Ott
      Sylvia Fuller
      Susanne Heiniger
      Janet Schneider
      Julia Clancy
      Bill Ott
      Julia Heiniger
      James Sommer
      Sylvia Steel
      James Clancy
      Bob Sommer
      Susanne White
      Andrew Smith
      Bill Sommer
      Bob Ringer
      Michael Ott
      Mary King
      Julia May
      George Karsen
      John Steel
      Michael Clancy
      Andrew Heiniger
      Mary Karsen
      Susanne Miller
      Bill King
      Robert Ott
      Susanne Smith
      Sylvia Ott
      Janet May
      Andrew May
      Janet Fuller
      Robert White
      George Fuller
      807: www@animal $->




            Unassigned Unassigned
            vegandy@gmail.com vegandy
            0 Vote for this issue
            0 Start watching this issue