Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Load Oracle JDBC Driver by reflection.

843859Jul 23 2007 — edited Aug 7 2007
Hi!
I'm trying to load driver by reflection like this,
try {
  URL ora8libURL = new URL("file:///C:/oracle/product/10.2.0/clientDev/jdbc/lib/classes12.jar");
  Class.forName("oracle.jdbc.OracleDriver", true, URLClassLoader.newInstance(new URL[]{ora8libURL}));
  
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while(drivers.hasMoreElements())
    {
      Driver drv = drivers.nextElement();
      System.out.println(drv.getClass().getName());
    }

  conn = DriverManager.getConnection("jdbc:oracle:thin:@//192.168.186.13:1521/rdb817","user","password");
}
catch(ClassNotFoundException ex) {ex.printStackTrace();}
catch(MalformedURLException ex) {ex.printStackTrace();}
catch (SQLException ex) {ex.printStackTrace();}
but i've got this error:
sun.jdbc.odbc.JdbcOdbcDriver

java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@//192.168.186.13:1521/rdb817
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)

...
However, when i specify driver explicit in classpath it works fine.

Help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 4 2007
Added on Jul 23 2007
14 comments
973 views