java - Apache Derby Driver Not Loaded Automatically -


i'm confused loading database driver apache derby. in it's documentation said that:

"if application runs on jdk 6 or higher, not need explicitly load embeddeddriver. in environment, driver loads automatically." https://db.apache.org/derby/docs/10.7/devguide/cdevdvlp40653.html


my connection url is:

jdbc:derby:testdb;create=true 


when try connect java derby without loading driver, following error:

error: java.sql.sqlexception: no suitable driver found jdbc:derby:testdb 


if load driver explicitly adding following line, error goes away.

class.forname("org.apache.derby.jdbc.embeddeddriver").newinstance(); 


now question why should need load driver explicitly? i'm running database application on eclipse reference jre7. why isn't loaded automatically?

this behavior responsibility of jdk's drivermanager class, not of derby itself. can read drivermanager class here: http://docs.oracle.com/javase/7/docs/api/java/sql/drivermanager.html

all derby provide jdbc driver proper meta-inf.

i think drivermanager behavior may depend on details of classpath.

if derby.jar in system classpath, automatic loading occur. if derby.jar in container separate classloader, such servlet containers, application servers, or sophisticated ides, aren't in classes searched drivermanager when initialized.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -