0

So, I was looking to solve this error java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver, but idk why my folder configuration is different from all the post i've found.

The steps i'm doing:

Tools>Libraries>Add jar/Folder

Library Menu

After that I don't know what to do there is like 50 different folders and I've added the libreries to Java DB Driver and even added a folder called Oracle but i'm nowhere near to make this work.

I even installed older versions of netbeans but I get the same window and options when it is supposed to just let me right click on project then Library>Add jar/Folder as mentioned here.

Edit: This is a desktop project, I'm using Netbeans 12.4 (but I also downloaded version 12.3, 12.0), the project was created from 0 with Netbeans 12.4 with these steps:

New project>Java with Maven>Java application>Change name and other information>Finish

After that just added a package then a JFrame, JPanel and a button and tried to add the ojdbc8.jar

I configured the service as @Trashgod said and was able to see the tables, views, etc but still got the same error.

Ezequiel
  • 79
  • 1
  • 8
  • Look in `Window > Services > Databases > Drivers`; right-click to configure. – trashgod Nov 25 '21 at 19:14
  • @trashgod Have you any post or refference about how to use it that way?, because I have it working the way you said, I can see the tables and views but when calling Class.forName("oracle.jdbc.driver.OracleDriver"); i'm still getting the same error about the driver missing. – Ezequiel Nov 25 '21 at 19:32
  • For clarification: Do you want to add a JAR to one specific Java project in NetBeans? If that is the case, then it depends on what type of Java project you have - for example Ant-based, Maven-based, Gradle-based. You made that choice when you created the project. And the steps will be different depending on that choice. (Personally I very rarely make changes to the NetBeans-wide libraries in the way you show - instead I add JARs to specific projects.) – andrewJames Nov 25 '21 at 20:17
  • @andrewJames Yes, I just need it in this project, it is a maven-based project, I used to work with eclipse and that is the way we added libraries there and as fas as I know, netbeans used to work the same way but the company where I work decided that we are just allowed to work with netbeans and now i'm stuck in this part and can't find a way to do it. For more clarification if it is possible to add it global I have no problem with that either. – Ezequiel Nov 25 '21 at 20:57
  • 1
    A Maven-based project has a POM (`pom.xml`), which is where you add your library dependencies. I feel like I may be missing the point, since that should be true regardless of the IDE you are using. – andrewJames Nov 25 '21 at 21:13
  • @andrewJames is correct; your use of the Ant Library Manager led me to infer that you were working on an [tag:ant] project; you may want to look [here](https://stackoverflow.com/search?tab=votes&q=%5bjava%5d%20oracle%20jdbc%20maven) and [edit] your question to clarify. – trashgod Nov 25 '21 at 23:57
  • Another question for clarification: Is your application a web-app, which is deployed as a WAR (or maybe a EAR) in a container such as Tomcat, Glassfish, etc.? Or is it a standalone Java application? I ask because that can affect where/how you need to add your database driver's JAR file. Please [edit] your question to provide all of this missing information. (And be aware there are many, many questions already about DB driver `ClassNotFoundException` problems on SO - so your problem has probably already been asked and answered here). – andrewJames Nov 26 '21 at 00:59
  • @andrewJames hmm well thats weird I don't seem to find any pom.xml file on any of my projects that I made in eclipse (which is where I started working with java like half a year ago), all I can find is a .project file and a .classpath file which contains the path for the jar files I added. Forgive me if im doing something wrong but its my first time working with ant-maven-gradle kind of projects. If I find a way to do it that is already here then i'm closing the post – Ezequiel Nov 26 '21 at 15:05
  • (1) What version of NetBeans are you using? (2) How did you create the project in NetBeans? Did you import it from existing sources? Create a new NetBeans project? Something else? Can you describe the specific steps? Please [edit] your question to provide the missing info. – andrewJames Nov 26 '21 at 15:51
  • Thanks - and sorry, you mentioned the version in the title (I missed that). So you _are_ creating a Maven project, and therefore there _should_ be a `pom.xml` file, automatically created - it should be in the "Project Files" folder. – andrewJames Nov 26 '21 at 16:30
  • @andrewJames yes, in the current project I have that file, I was looking at some of the post that trashgod told me [like](https://stackoverflow.com/questions/4491199/build-maven-project-with-propriatery-libraries-included/4491343#4491343) but idk where to get the artifactid, etc that is asking and where to add that, tried to add it in the dependencies folder then add dependency but it doesn't seems like that is what I want. Might just be because i'm new to the IDE. – Ezequiel Nov 26 '21 at 16:45
  • You edit your `pom.xml` and create a ` ... ` section (if it does not already exist). To know what specific dependency you need to add, you can use the [Maven Central repository](https://mvnrepository.com/). For example, if you want to add an Oracle driver, [here is one example](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc10/19.12.0.0). That shows you the group and artifact IDs. However, I don't know which of the _many, many_ Oracle drivers you need (there are different versions of the driver for different versions of Oracle DB & Java). – andrewJames Nov 26 '21 at 16:55
  • Once you find the right driver, you can copy/paste that XML from Maven into your POM file, in the `dependencies` section. See also tutorials such as [this one](http://tutorials.jenkov.com/maven/maven-tutorial.html) and others. – andrewJames Nov 26 '21 at 16:57
  • @andrewJames That just worked, had to add the section (it was not in the POM file) and inside that add the dependency from the repository link you gave me, just one last thing, I have to delete this question right? – Ezequiel Nov 26 '21 at 17:15
  • Good news. You do not _have_ to delete this question. The community may _vote_ to have it deleted. You can _choose_ to delete it if you think it will not be helpful to anyone else in the future. You can _choose_ to [write your own answer](https://stackoverflow.com/help/self-answer) if you want to. You may also want to check if there is already another question and answer which covers the same material - in which case you can flag your question as a _duplicate_ of that other question. – andrewJames Nov 26 '21 at 17:34

1 Answers1

0

What worked for me was what @andrewJames said, editing POM.xml by adding the tag <dependencies> ... </dependencies> which was not automatically created by Netbeans and inside that adding the xml from Maven Central repository ojdbc8 (or whatever version you need), after that just run the project and it will download automatically the driver.

I'm keeping the question because as a new user of Netbeans, if the program doesn't add important tags like <dependencies> ... </dependencies> and you just come and try to add the <dependency> ... </dependency> tag which is suggested in many questions, but none of them tells you that you should have such a tag in the first place, even if its correct you will be getting an error.

Ezequiel
  • 79
  • 1
  • 8