0

Project tree:

ReparacionesElectronicas

  • controlador: Principal.java VClientesController.java
  • modelo: Conexion.java Reparacion.java ReparacionDao.java
  • recursos: Utilidades.java
  • -recursos.imagenes: some .png files
  • vista: VReparaciones.fxml

My "setup":

  • Netbeans 15
  • Java JDK 11
  • JavaFX SDK 18
  • Oracle XE 11.2
  • I added JBDC 6 Driver (ojdbc6.jar) to my path project.
  • I added JBDC Driver to my windows variables.
  • I added JDBC Driver to my "libriries" of my project.
  • I added a named JavaFX library with 8 files of my javafx sdk to my netbeans.
  • I added JavaFX library () to my project in Properties>Libraries>Compile>classpath + Properties>Libraries>Run>modulepath
  • I added "--module-path /path/to/javafx/lib --add-modules=javafx.controls,javafx.fxml" to Properties>Run>VM Options

That's my connection file:

package modelo;

import java.sql.Connection;
import java.sql.DriverManager;
import javafx.scene.control.Alert;

public class Conexion {
    Connection con;
    String url="jdbc:oracle:thin:@localhost:1521:XE";
    String user="hr";
    String pass="pass";
    
    public Connection conectar(){
        try {
            Class.forName("Oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection(url,user,pass);
        } catch (Exception e) {
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("Ventana de error");
            alert.setHeaderText(e.getMessage());
            System.out.println(e.getMessage());
            alert.setContentText("Acepta para continuar");
            alert.showAndWait();
        }
        return con;
    }
    
    public void desconexion(){
        try {
            con.close();
        } catch (Exception e) {
            System.out.println("Error al desconectarse" + e.getMessage());
        }
    }
}

The error with system out: Oracle.jdbc.driver.OracleDriver

edit: I added "e.printStackTrace();" under the line "alert.setHeaderText(e.getMessage());" and I get this:

    java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
Oracle.jdbc.driver.OracleDriver
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at modelo.Conexion.conectar(Conexion.java:23)
    at modelo.ReparacionDao.listar(ReparacionDao.java:27)
    at controlador.VClientesController.actualizarTabla(VClientesController.java:126)
    at controlador.VClientesController.initialize(VClientesController.java:110)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2655)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3331)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3287)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3255)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3227)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3203)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3196)
    at controlador.Principal.start(Principal.java:30)
    at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
    at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics@18/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics@18/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@18/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:834)

I cannot stop thanking you for the speed with which you have helped me, it has surprised me a lot.

Another strange thing is that if I remove the imports .sql.Connection; and .sql.DriverManager; Netbeans does not suggest the correct imports to me. [1]: https://i.stack.imgur.com/OS04W.png

ERROR DRIVER SOLVED editing "Class.forName("Oracle.jdbc.driver.OracleDriver");" to Class.forName("oracle.jdbc.driver.OracleDriver"); or removing that line.

The new error:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
    at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1082)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
    at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javafx.fxml.LoadException: 
/G:/curso/programacion/ReparacionesElectronicas/build/classes/vista/VReparaciones.fxml

    at javafx.fxml@18/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2685)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3331)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3287)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3255)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3227)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3203)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3196)
    at controlador.Principal.start(Principal.java:30)
    at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
    at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics@18/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics@18/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@18/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    ... 1 more
Caused by: java.lang.NullPointerException
    at controlador.VClientesController.actualizarTabla(VClientesController.java:131)
    at controlador.VClientesController.initialize(VClientesController.java:110)
    at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2655)
    ... 17 more
Exception running application controlador.Principal
C:\Users\peked\AppData\Local\NetBeans\Cache\15\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\peked\AppData\Local\NetBeans\Cache\15\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 1 second)

My main class:

package controlador;


import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author Daniel
 */
public class Principal extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/vista/VReparaciones.fxml"));
        
        Scene escena = new Scene(root);
        stage.setTitle("Reparaciones Activas");
        stage.setScene(escena);
        stage.show();
    }

}
Daniel
  • 1
  • 2
  • You are using NetBeans. What type of Java project is this? For example, was it created using File > New Project > Java with Ant? Or some other way? – andrewJames May 11 '23 at 18:19
  • "_I added JBDC Driver_" - Can you be more specific? What is the driver file name? – andrewJames May 11 '23 at 18:19
  • 1
    If this is an Ant project, you add the Oracle JDBC driver (the JAR file) to your project by going to File > Project Properties > Libraries > Classpath - then click on the `+` sign on the right hand side of `Classpath` and choose `Add JAR/Folder`. It is difficult to tell if this is one of the things you already tried... but certainly all those "module" related attempts are not relevant. The JAR needs to be on the **runtime classpath** of your app. – andrewJames May 11 '23 at 18:25
  • 1
    Write `e.printStackTrace()` to log the error. Copy the full stack trace and provide it in the question as text, formatted as code. – jewelsea May 11 '23 at 18:28
  • 1
    Info on dialog alerts with exceptions, from [makery](https://code.makery.ch/blog/javafx-dialogs-official/): – jewelsea May 11 '23 at 18:30
  • 1
    Check NetBean's Window > Services > Databases to see existing driver(s); Oracle Thin (`oracle.jdbc.OracleDriver`) is likely already present; note the case of the driver's name. – trashgod May 11 '23 at 18:37
  • thanks thanks thanks. JDBC driver is ojdbc6.jar. My project is Java with Ant> Java Application. I added jar file driver to my Propierties>Libraries>Run>classpath but the error was not solved. I added the "e.printStackTrace()" to the post. I don't understand you jewelse I'm so sorry, thanks for trying to help me. Trashgod, I did it and something is good, I wasn't connected to my database but now I do :) (jdbc:oracle:thin:@localhost:1521:XE [database_name on data_table_I_think]) – Daniel May 11 '23 at 19:09
  • @Daniel: Try `Class.forName("oracle.jdbc.OracleDriver"`, which is a [legacy](https://www.baeldung.com/java-jdbc-loading-drivers). – trashgod May 11 '23 at 19:19
  • @legacy I tried but It does not work. – Daniel May 11 '23 at 19:24
  • @trashgod I put a comment with all helps but It doesn't work. – Daniel May 11 '23 at 19:28
  • @andrewJames I put in a comment above the attempts that did not contribute anything new, always the same error. – Daniel May 11 '23 at 19:42
  • You shouldn't even need `Class.forName`, for [example](https://stackoverflow.com/a/34742409/230513). – trashgod May 11 '23 at 22:19
  • Your `ClassNotFoundException` is arising from your call to `Class.forName("Oracle.jdbc.driver.OracleDriver");`, and the reason for that is probably that you specified _"Oracle."_ (upper case `O`) instead of _"oracle."_ (lower case `o`). But I agree with @trashgod that you don't even need to call `Class.forName()`, so rather than fixing your invalid package name just comment out that line and see what happens. – skomisa May 12 '23 at 00:12
  • Once you have removed that line update your question, because if you still have a problem it definitely won't be the one that you have currently posted. Also, from your stack trace, line 23 in class `Conexion` doesn't correspond to your call to `Class.forName()` in the code you have posted. Please be sure to post the _exact source code_ you are running. – skomisa May 12 '23 at 00:19
  • @trashgod well, that's correct!! If I delete that line, I haven't got driver error but if I change Oracle. to oracle. neither!!! – Daniel May 12 '23 at 03:27
  • @skomisa yessssssssssssssssss, driver error SOLVED (Although I get more errors that seem not to be a connection problem.) – Daniel May 12 '23 at 03:29
  • And how was your error solved? In your previous comment you said: *"If I delete that line, I haven't got driver error but if I change Oracle. to oracle. neither"*, so I guess neither deleting the `Class.forName` instruction nor changing the driver fully qualified name worked, so what did work? – jewelsea May 12 '23 at 03:59
  • @jewelsea both works with driver error!! The current error is not the connection's fault, I think. – Daniel May 12 '23 at 04:04

0 Answers0