aspose file tools*
The moose likes JDBC and the fly likes Database can connect in Service Netbeans screen but not using code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database can connect in Service Netbeans screen but not using code" Watch "Database can connect in Service Netbeans screen but not using code" New topic
Author

Database can connect in Service Netbeans screen but not using code

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
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: 89
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: 2500
    
    8

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 and ITIL foundation
youtube channel
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database can connect in Service Netbeans screen but not using code