Can't connect local Oracle database

Hello!
I’m using liquibase docker container:

docker run --rm -v I:\Projects\Liquibase:/liquibase/changelog liquibase/liquibase --defaultsFile=/liquibase/changelog/configs/liquibase.properties status

I’m trying to connect with the local Oracle database and I’m getting the following error:

Connection could not be created to jdbc:oracle:thin:@localhost:1521:xe with driver oracle.jdbc.OracleDriver.  IO Error: The Network Adapter could not establish the connection

liquibase.properties file:

url: jdbc:oracle:thin:@localhost:1521:xe
username: men
password: 1

But connecting via SQL*Plus or SQL Developer is successful.

>sqlplus men/1@localhost:1521/xe
...
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
SQL>

>tnsping localhost:1521/xe
 ...
Used HOSTNAME adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=xe))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
OK (0 msec)

What am I doing wrong?

Hello,

Regards,
Ahmed.

Thank you, Ahmed, for the feedback.

  • classpath: /liquibase/changelog/OJDBC/8/ojdbc8.jar
  • Oracle Database 11g Express Edition Release 11.2.0.2.0 + JDK 8 + ojdbc8
  • Step1 - :white_check_mark:

I still get the error.

Hello,

Try to check the listener is up or down.
I think that you have issue establishing DB connection through network.
Install SQL developper to check if your DB is accessed remotely or not.

Regards,
Ahmed.

hello,

I have done the test today.

1- Here are the config used:

Make sure it’s working before save with clicking on “test” button.

2- Here is the content of my liquibase.properties :

driver: oracle.jdbc.OracleDriver
classpath: ./ojdbc8.jar
url: jdbc:oracle:thin:@localhost:1521:XE
username: hr
password: hr

The ojdbc8.jar was downloaded from this link :

https://www.oracle.com/database/technologies/jdbc-ucp-122-downloads.html

3- Here it’s my changelog file test.xml:
Capture2

4- Here are the results after tests :

Regards,
Ahmed.

Hello!

Here are my configs:

  1. Microsoft Defender - disable
    Antivirus - disable

  2. SQL Developer:

  1. liquibase.properties:

    driver: oracle.jdbc.OracleDriver
    classpath: /liquibase/changelog/ojdbc8.jar
    url: jdbc:oracle:thin:@localhost:1521:xe
    username: men
    password: 1

  2. Run liquibase docker and SQL*PLus connect:

Hello!

I installed Liquibase and it’s works for me.
But when I use Liquibase with docker, I still get the error.

If you’re running it in docker, it’ll try to use the internal container loop back address and will fail connecting to the host. You’ll need to specify an external IP address.

root@872d975d2509:/wd# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.0.5  netmask 255.255.0.0  broadcast 172.18.255.255
        ether 02:42:ac:12:00:05  txqueuelen 0  (Ethernet)
        RX packets 9189  bytes 4837083 (4.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9658  bytes 2342502 (2.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 386  bytes 20562 (20.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 386  bytes 20562 (20.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Thank you, erinlkolp!
You were right. Your advice helped me solve the problem.

Му liquibase.properties:

driver: oracle.jdbc.OracleDriver
classpath: /liquibase/changelog
url: jdbc:oracle:thin:@192.168.1.80:1521:xe
username: men
password: 1
changeLogFile: mychangelog.oracle.sql

Also, for Oracle 11g, I had to upgrate the time zone file, because I got the error:

Starting Liquibase at 16:31:20 (version 4.3.5 #62 built at 2021-04-29 18:31+0000)
Unexpected error running Liquibase: liquibase.exception.DatabaseException: 
liquibase.exception.DatabaseException: Connection could not be created 
to jdbc:oracle:thin:@192.168.176.1:1521:xe with driver oracle.jdbc.OracleDriver.  
ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found

I used this instruction: Steps to Upgrade Time Zone File and Timestamp with Time Zone Data

I took the time zone file timezlrg_31.dat and timezone_31.dat from oracle-database-xe-18c-1.0-1.x86_64 image and put it in $ORACLE_HOME/oracore/zoneinfo.

Here are next my steps:

C:\Users\Men>sqlplus /nolog                       
                                                                            
SQL*Plus: Release 11.2.0.2.0 Production on ╤с ╚■э 12 21:05:40 2021
                                                                            
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
                                                                            
SQL> conn men/1 as sysdba                                          
Connected.                                                                  

SQL> shutdown                                                               
Database closed.                                                            
Database dismounted.                                                        
ORACLE instance shut down.                                                  

SQL> startup upgrade                                                        
ORACLE instance started.                                  
...                                
Database mounted.                                             
Database opened.                                                

SQL> exec DBMS_DST.BEGIN_UPGRADE(31);
PL/SQL procedure successfully completed.   
                                                                            
SQL> shutdown                                                               
Database closed.                                                            
Database dismounted.                                                        
ORACLE instance shut down.                            

SQL> startup                       
ORACLE instance started.
...

Thank you Ahmed, erinlkolp for your help!