Search code examples
javajdbcjava-8derby

Why does Derby have to be manually added even though its apart of JDK


A little while ago I asked a question about a no driver error. I was able to figure it out by adding the C:\Program Files\Java\jdk1.8.0_112\db\lib directory to my eclipse project manually. I'm just wondering why it does. Especially when it seems like all of the other jar files in JDK 8 run automatically. Maybe.


Solution

  • First, you are correct that you need to add the Driver JAR file to your classpath. The Oracle documentation for JavaDB says so: see http://docs.oracle.com/javadb/10.10.1.2/getstart/twwdactivity4.html for example.

    Why? Well this is conjecture, but suppose that you wanted to run a Java program that talked to a MySQL database. If the JAR files containing the Derby drivers were added to the JVM's bootstrap classpath automatically, then the Derby Driver classes would typically be loaded (by the DriverManager framework), even though it is only the MySQL Driver class that you want to use. Many people would consider loading unwanted drivers to be a defect ... if the JVM did that.