File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLClassLoader for loading JDBC driver...

 
Tom Wang
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Abdul Narayan D'souza TP
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic