I was trying to create a very simple app where at loading the main window the program connects to the DB.
If I comment the part of the connection to the DB it works fine. The app shows no error, throws no exception, so I cannot figure out what’s wrong. I post my code:
public final class Database {
private final String dbURL = "jdbc:oracle:thin:@" + dbHost + ":" + dbPort + ":" + dbService;
private final String dbDriver = "oracle.jdbc.driver.OracleDriver";
private Connection connection = null;
public Database() {
try {
System.out.println("Aqui 1");
Class.forName(dbDriver);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void connect() {
System.out.println("Dentro");
try {
connection = DriverManager.getConnection(dbURL, dbUser, dbPass);
} catch (SQLException ex) {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void disconnect() {
try {
connection.close();
} catch (SQLException ex) {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void numeroErrores(String dependencia){
System.out.println("Hola");
connect();
disconnect();
System.out.print("Adios");
}
}
the dbUser, dbPass, dbHost, dbPort, dbService are set to their correct value, I’ve checked and rechecked them, also I am sure I’ve added the correct jar file of the oracle-jdbc. It kind of hangs (I say kind of ’cause no error no nothing is shown but the System.out.println I put there) when calling the connect() method.
Any idea?
There are not enough debug prints or catch statements
Try catching both general Exception and Throwable, see if that adds data
If you dont have a debugger, add debug prints on every line so you know exactly where you are
If you have the ojdbc6.jar, try adding this right before DriverManager.getConnection:
just to make sure