This method has the return type Connection
, but in blocks catch
there is no return conn
and there is no compilation or execution error. I think it's for throws
and throw
but I do not know exactly why.
public static Connection getConexao() throws SQLException, ClassNotFoundException {
Connection conn = null;
try {
Class.forName(DRIVER_CONEXAO);
conn = DriverManager.getConnection(STR_CONEXAO + DATABASE, USUARIO, SENHA);
return conn;
} catch (ClassNotFoundException e) {
throw new ClassNotFoundException(
"Driver MySql não foi encontrado " + e.getMessage());
} catch (SQLException e) {
throw new SQLException("Erro ao conectar "
+ "com a base de dados" + e.getMessage());
}
}