class loading

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

class loading

Robert Bram-2

Hi All,

I am having a little trouble loading some classes. I tried this method first.

addClassPath( "C:\\java\\oracle\\ojdbc14_g.jar" );
addClassPath( "C:\\java\\oracle\\ojdbc14.jar" );

import java.sql.*;

Class.forName("oracle.jdbc.driver.OracleDriver");

And got the dreaded class not found exception:
Target exception: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

But when I add the jars to beanshell's class path (via java -cp ...) the Class.forName() works.

What is wrong with my usage of addClassPath above?

Kind Regards,

Rob
:)



This email and any attachments may contain privileged and confidential information and are intended for the named addressee only. If you have received this e-mail in error, please notify the sender and delete this e-mail immediately. Any confidentiality, privilege or copyright is not waived or lost because this e-mail has been sent to you in error. It is your responsibility to check this e-mail and any attachments for viruses.  No warranty is made that this material is free from computer virus or any other defect or error.  Any loss/damage incurred by using this material is not the sender's responsibility.  The sender's entire liability will be limited to resupplying the material.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: class loading

Alexey Zinger
--- Robert Bram <[hidden email]> wrote:

>
> Hi All,
>
> I am having a little trouble loading some classes. I tried this method first.
>
> addClassPath( "C:\\java\\oracle\\ojdbc14_g.jar" );
> addClassPath( "C:\\java\\oracle\\ojdbc14.jar" );
>
> import java.sql.*;
>
> Class.forName("oracle.jdbc.driver.OracleDriver");
>
> And got the dreaded class not found exception:
> Target exception: java.lang.ClassNotFoundException:
> oracle.jdbc.driver.OracleDriver
>
> But when I add the jars to beanshell's class path (via java -cp ...) the
> Class.forName() works.
>
> What is wrong with my usage of addClassPath above?
>
> Kind Regards,
>
> Rob
> :)

addClassPath command manipulates BeanShell's internal class loader, whereas
Class.forName specifically queries JVM's top-level class loader.  Compare that
with Thread.currentThread().getContextClassLoader() or simply this:

print(oracle.jdbc.driver.OracleDriver.class);

after calling addClassPath.

Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: class loading

Robert Bram-2
In reply to this post by Robert Bram-2

Hi Alexey,

> addClassPath command manipulates BeanShell's internal class loader, whereas
> Class.forName specifically queries JVM's top-level class loader.  Compare that
> with Thread.currentThread().getContextClassLoader() or simply this:

> print(oracle.jdbc.driver.OracleDriver.class);

>after calling addClassPath.

This doesn't seem to work for me. Now I have this:

try {
  addClassPath( "C:\\java\\oracle\\ojdbc14_g.jar" );
  addClassPath( "C:\\java\\oracle\\ojdbc14.jar" );
  // print(oracle.jdbc.driver.OracleDriver.class);
  Thread.currentThread().getContextClassLoader().loadClass("oracle.jdbc.driver.OracleDriver");

  import java.sql.*;
  import oracle.jdbc.driver.*;

  // do oracle things..

} catch ( Throwable e ) {
    print( e );
}

And the output is:

class oracle.jdbc.driver.OracleDriver
java.sql.SQLException: No suitable driver

Kind Regards,

Rob
:)

This email and any attachments may contain privileged and confidential information and are intended for the named addressee only. If you have received this e-mail in error, please notify the sender and delete this e-mail immediately. Any confidentiality, privilege or copyright is not waived or lost because this e-mail has been sent to you in error. It is your responsibility to check this e-mail and any attachments for viruses.  No warranty is made that this material is free from computer virus or any other defect or error.  Any loss/damage incurred by using this material is not the sender's responsibility.  The sender's entire liability will be limited to resupplying the material.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: class loading

Alexey Zinger
--- Robert Bram <[hidden email]> wrote:

>
> Hi Alexey,
>
> > addClassPath command manipulates BeanShell's internal class loader, whereas
> > Class.forName specifically queries JVM's top-level class loader.  Compare
> that
> > with Thread.currentThread().getContextClassLoader() or simply this:
>
> > print(oracle.jdbc.driver.OracleDriver.class);
>
> >after calling addClassPath.
>
> This doesn't seem to work for me. Now I have this:
>
> try {
>   addClassPath( "C:\\java\\oracle\\ojdbc14_g.jar" );
>   addClassPath( "C:\\java\\oracle\\ojdbc14.jar" );
>   // print(oracle.jdbc.driver.OracleDriver.class);
>  
>
Thread.currentThread().getContextClassLoader().loadClass("oracle.jdbc.driver.OracleDriver");

>
>   import java.sql.*;
>   import oracle.jdbc.driver.*;
>
>   // do oracle things..
>
> } catch ( Throwable e ) {
>     print( e );
> }
>
> And the output is:
>
> class oracle.jdbc.driver.OracleDriver
> java.sql.SQLException: No suitable driver
>
> Kind Regards,
>
> Rob
> :)

I'd be interested to know which statement in your code causes this exception to
be thrown.  My bet is that it's the first time you attempt to connect using
DriverManager or some similar JVM-wide facility.  I've run into situations,
where simply loading a driver class did not do the trick and I had to
explicitly register the driver with DriverManager using registerDriver(Driver) method.

Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: class loading

Robert Bram-2
In reply to this post by Robert Bram-2

Hi Alexey,


> I'd be interested to know which statement in your code causes this exception to
> be thrown.  My bet is that it's the first time you attempt to connect using
> DriverManager or some similar JVM-wide facility.  I've run into situations,
> where simply loading a driver class did not do the trick and I had to
> explicitly register the driver with DriverManager using registerDriver(Driver) method.

At last! This worked:

addClassPath( "C:\\java\\oracle\\ojdbc14_g.jar" );
addClassPath( "C:\\java\\oracle\\ojdbc14.jar" );
java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());


For interest, the code was this:

String url = "jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)"
        + "(ADDRESS=(PROTOCOL=TCP)(HOST=udorac01vip)(PORT=1521))"
        + "(ADDRESS=(PROTOCOL=TCP)(HOST=udorac02vip)(PORT=1521))"
        + "(CONNECT_DATA=(SERVICE_NAME=ORDCORES.cmltd.net.au)))";
Connection con = DriverManager.getConnection(url, "rbram", "apple42");
String sql = "select * from folder";
Statement stmt = con.createStatement();
stmt.executeQuery(sql);
ResultSet rs = stmt.getResultSet();
while(rs.next()) {
        print(rs.getString("NAME"));
}
stmt.close();




Kind Regards,

Rob
:)


This email and any attachments may contain privileged and confidential information and are intended for the named addressee only. If you have received this e-mail in error, please notify the sender and delete this e-mail immediately. Any confidentiality, privilege or copyright is not waived or lost because this e-mail has been sent to you in error. It is your responsibility to check this e-mail and any attachments for viruses.  No warranty is made that this material is free from computer virus or any other defect or error.  Any loss/damage incurred by using this material is not the sender's responsibility.  The sender's entire liability will be limited to resupplying the material.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users