Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Driver / Specification

 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have made the assumption that when an application makes a call to DriverManager.getConnection, that the DriverManager would call acceptsURL on all of its registered drivers (java.sql.Driver implementations). This assumption appears to be false, as my observed behaviour is that a call to connect is made before anything, and then no other calls to the Driver are made.

So I ask, why is this so? Would a correct Driver implementation call acceptsURL from its connect method? i.e.



This seems like an odd thing to do, hence my speculation that I am misunderstanding something. I originally guessed that the DriverManager was acting this way because only one Driver implementation was registered - I then went on to register two Driver implementations and observed the same behaviour. The following test case only registers one Driver implementation so that it is reproducable without any additional drivers. It requires a J2SE 1.2 or 1.3 compiler (a little bit of work would need to be done to get it to compile with 1.4 due to the additions to the JDBC API).

The observed output is:


I was expecting:


The test case involves three source files and can be executed with:



The three source files follow:







[ July 25, 2004: Message edited by: Tony Morris ]

[ July 25, 2004: Message edited by: Tony Morris ]
[ July 25, 2004: Message edited by: Tony Morris ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe I have just found my answer:


When the DriverManager is trying to establish a connection, it calls that driver´┐Żs
connect method and passes the driver the URL. If the Driver implementation
understands the URL, it will return a Connection object; otherwise it returns null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic