• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

URLClassLoader for loading JDBC driver...

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello :
I'm trying to use URLClassLoader to load JDBC driver without
setting CLASSPATH , belows are my codes:

URL v_url = new URL("http://localhost:8080/try/classes12.jar");
URLClassLoader v_classLoader = new URLClassLoader(new URL[] { v_url });
Class.forName("oracle.jdbc.driver.OracleDriver",true,v_classLoader);
String vs_url = "jdbc racle:thin:@192.168.1.3:1521:testMyDB";
String user = "user";
String pass = "pass";
Connection conn = DriverManager.getConnection(vs_url,user,pass);

...but I keep getting the error message like this:

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at tryJDBC.createConnection(tryJDBC.java:37)
at tryJDBC.main(tryJDBC.java:135)

Please help....thanks.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom,
Well u have successfully loaded the driver, otherwise u would get a
"ClassNotFound" Exception.

I guess there is a problem with your database url.
Just check it up with your driver's documentation.
 
Tom Wang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
I don't think the problem is because of the url, because the program above works fine if I added classes12.jar to the CLASSPATH.
I wonder if I can use URLClassLoader for loading the JDBC driver, then I won't have to copy the driver files to every users' computers...(My boss
doesn't want to use WEB...)
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic