开发者

JBoss v.s. Tomcat JDBC driver registration discrepency

I have a JDBC drive that I used to use just fine with JBoss 7 I have since switched to Tomcat (also v7) for faster deployment while debugging and noticed that the same JDBC driver was not loaded automatically anymore. I had to register it manually myself, which then worked. Is this a lmiitation in Tomcat that doesn't exist in JBoss?

I had thought that JBoss uses Tomcat internally....

P.S: I am running everything against JRE 1.6 so automatic registration sh开发者_JAVA技巧ould be a given.


The automatic JDBC driver registration depends on the Driver implementation providing a static initializer block that invokes DriverManager.registerDriver(...); the block is invoked only when the Driver class is loaded. Chances are that the driver implementation does not have such a static initializer, or that the application server is not loading the class (unlikely).

If the driver claims to be a JDBC 4.0 compliant driver, consider filing a bug if there is no static initializer block, as Section 9.2 of the JDBC 4.0 specification specifically states (emphasis mine):

JDBC drivers must implement the Driver interface, and the implementation must contain a static initializer that will be called when the driver is loaded. This initializer registers a new instance of itself with the DriverManager, as shown in CODE EXAMPLE 9-1.

public class AcmeJdbcDriver implements java.sql.Driver {
  static {
    java.sql.DriverManager.registerDriver(new AcmeJdbcDriver());
  }
  ...
}

CODE EXAMPLE 9-1 Example static initializer for a driver implementing java.sql.Driver

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜