I'm fairly new to programming and trying to connect to a DB using HTML, I'm using Wildfly, Apache NB and Derby in this case, hosted locally, the thing is that the browser gives me the following error after I try to log in with the credentials that I have created in the DB: [Login screen1
java.lang.NullPointerException: Cannot invoke "java.sql.Connection.prepareStatement(String)" because the return value of "model.Conexion.getConexion()" is null
So I went to NB Conexion.java to check the getter but I cannot seem to find what is the issue here is the code.
Also, I have tried this with different versions of JDK, JRE more specifically u144 and u271 tried with GlassFish5, Payara and Wildfly and still no luck.
I would really appreciate any help on this as my semester depends a lot on this
package model;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Conexion {
private static Conexion conexion;
private static final String BDURL= "jdbc:derby://localhost:1527/proyectohtml;user=ROOT;password=1234";
private static Connection conn;
private Conexion(){
try {
Class.forName("org.apache.derby.jdbc.ClientDriver").getDeclaredConstructor().newInstance();
conn=DriverManager.getConnection(BDURL);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SQLException ex) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static synchronized Connection getConexion() {
if (conexion==null) {
conexion=new Conexion();
}
return conn;
}
}