| Author |
Database can connect in Service Netbeans screen but not using code
|
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
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
Joined: Apr 04, 2009
Posts: 84
|
|
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
Joined: Dec 20, 2006
Posts: 2343
|
|
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.
|
OCUP UML fundamental
ITIL foundation
|
 |
Ireneusz Kordal
Ranch Hand
Joined: Jun 21, 2008
Posts: 423
|
|
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.
|
 |
 |
|
|
subject: Database can connect in Service Netbeans screen but not using code
|
|
|