Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database can connect in Service Netbeans screen but not using code

 
Colm Dickson
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

In Netbeans I can create a connection to my oracle database using the tnsname option under the services window. After pointing to the classes111.zip file that I have saved to my C drive, I then follow the wizard and I have a database connection and can see tables etc.. however, when using the
Class.forName("oracle.jdbc.OracleDriver") in my java class and I have the path of my classes111.jar in my classpath the java class will not compile due to the classdef not found error.


Why will the Netbeans wizard create a connection when I poitnto the driver and add the driver but the java project itself will not?

Thanks,

Colm
 
Colm Dickson
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I have resolved this matter. I always knew it was classpath linked but for anyone else who may have the same issue, I found out where the JAVA_HOME was and added the classes111 library to the lib directory here. This directory was...

C:\Program Files\Java\jre6\lib

Having explored the classes111 library, I knew the directory structuctures contained therein and so I added




My call to Class.forName then worked so I just added the full path (C:\Program Files\Java\jre6\lib) to my classpath variable and then went into NetBeans, removed the import statement and ran the project and it worked.

Colm

 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Colm.
I would like to advise you to *not* store the jdbc classes in C:\Program Files\Java\jre6\lib .
That is in the Java installation structure, and I would not place additional files in there.
Place your libraries somewhere outside the java installation path, and use the classpath mechanism to properly point to them.

Your solution will break when you install a new java version.

 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Netbeans open project properties, display "libraries" window,
go to "Run" pane and check if there is Oracle driver jar there - if not, add it.
Driver classes are not imported by the source files (using "import" declaration")
and Netbeans cannot know that there are required and must be copied to the build directories
until you add libraries in the project properties.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic