Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2005

Tip: Looking for answers? Try searching our database.

Why can't the debugger find my JDBC Driver.

Thread view: 
Glenn McCall - 05 Jan 2005 08:58 GMT
I'm sure this is going to be one of those "can't see the forrest for the
trees" questions, but here goes.

I have a JDBC program which I am trying to debug in the NetBeans (v3.6)
bundled with the j2sdk (v1.4.2_04). My problem is that when I run under the
control of the debugger, I get a ClassNotFoundException when performing the
"Class.forName (myJDBCClass);" statement.
If I run the exact same program outside of the IDE or even within the IDE
(using the execute command) the "system" manages to find my JDBC class.

I have added the relevant jar to the classpath field in both the External
Execution and Debugger Execution properties. If I remove the Jar from the
classpath field in the "External Execution" properties, I get the
ClassNotFoundException. So it seems like I am hitting the right property for
external execution. But the property with the same name doesn't seem to work
in the Debugger Execution.

Below is the test program attempting to load a mysql driver. If i run it
within the IDE (Execute) or from the command prompt, it prints the message
"driver loaded".
If I run it under the control of the debugger (eg. Ctrl-F5) I get
"Exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
followed by a stack trace.

For what it is worth, my classpath environmental variable also nominates the
jar containing my JDBC driver. My OS is Windows 2K.

How can I get the debugger to recognise my jar?

TIA

package com.test;
public class TestA {
   public TestA() {
   }
   public static void main(String[] args) {
       try {
           Class.forName ("com.mysql.jdbc.Driver");
           System.out.println ("driver loaded");
       }
       catch (ClassNotFoundException e) {
           System.out.println ("Exception: " + e);
           e.printStackTrace ();
       }
   }
}
Glenn McCall - 06 Jan 2005 23:04 GMT
I haven't received any replies to this yet, so I am reposting to additional
newsgroups.

> I'm sure this is going to be one of those "can't see the forrest for the
> trees" questions, but here goes.
[quoted text clipped - 42 lines]
>    }
> }
Alex Kizub - 06 Jan 2005 23:28 GMT
Glenn:
Problem is definitely not in your code but in IDE configuration.
There is misunderstanding between what you think and IDE think.

This small method can help you to understand what IDE thinks. I cut it from
JWhich.
Simply include it for any class and call it with full class name. It will show
where is class located.
For none existing classes it will give you full classpath and you could
understand what IDE thinks.

public static String which(String className) {
 if (className == null ) className="java.lang.Object";

 if (!className.startsWith("/")) {
   className = "/" + className;
 }
 className = className.replace('.', '/');
 className = className + ".class";

 java.net.URL classUrl =
   new Object().getClass().getResource(className);

 if (classUrl != null) {
   className = ("\nClass '" + className +
     "' found in \n'" + classUrl.getFile() + "'");
 } else {
   className = ("\nClass '" + className +
     "' not found in \n'" +
     System.getProperty("java.class.path") + "'");
 }
return className;
}

Alex Kizub.
Glenn McCall - 09 Jan 2005 07:54 GMT
That's great thanks, I can see that my classpath does not include the mysql
jar when I run under debug. I even have a workaround - using
System.setProperty to set a classpath that *does* include my jar.

But I would rather not use the workaround - I would rather be able to set
the classpath via the IDE - I've quadruple checked and I have included the
mysql jar in the debugger properties "classpath". However when running in
debug mode, the classpath does not include the jar (or any of the other
additions I have made). Alex mentions a misunderstanding between what I
think and what the IDE thinks - I would like to clear up the
misunderstanding.

As per my original post - I've set the classpath properties correctly if I
simply "execute" my project. However, if I set the same property in the
debugger properties my entries do not appear to be picked up by the debugger
(the debugger console confirms this).

Is there a problem with the Netbeans IDE? Has anyone else experienced this
problem?
Or am I just not specifying the classpath correctly?
If I'm not setting it properly, which property do I set?

I'm currently going to Tools/Options - then in the tree I'm selecting
"Debugging and executing", then "debugger types", then "Default Debugging",
then in the properties fields, I'm clickin the ... associated with the entry
"classpath". I then click the "add jar button and select the mysql jar. I'm
confirming that the mysql jar is selected in the classpath text display in
the properties dialogue then clicking OK.
I've also tried setting the classpath in my project properties and my class
properties using a similar process (right click the project, select
properties etc).

Glenn Mc
Roland J Rankin Jr - 18 Jan 2005 22:31 GMT
> I'm sure this is going to be one of those "can't see the forrest for the
> trees" questions, but here goes.
[quoted text clipped - 5 lines]
> If I run the exact same program outside of the IDE or even within the IDE
> (using the execute command) the "system" manages to find my JDBC class.

With net beans it's better not to monkey around with the ClassPath
Variable and instead Mount the Jar. Any mounted File system or Archive
is automatically added to both the execute and the debug class path.

If your mounting too many file systems for your personal comfort you can
change the Property Hidden to true. On your archive librarys.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.