Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Created May 27, 2020 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasdarimont/c3d4a14185de16cb9c63bb994fc82b46 to your computer and use it in GitHub Desktop.
Save thomasdarimont/c3d4a14185de16cb9c63bb994fc82b46 to your computer and use it in GitHub Desktop.
Docker Oracle Database

See https://apex.oracle.com/pls/apex/germancommunities/dbacommunity/tipp/6241/index.html

Create database

docker run -d -it -p 1521:1521 --name oracle-db store/oracle/database-enterprise:12.2.0.1-slim

Create user

docker exec -it oracle-db bash -c "source /home/oracle/.bashrc; sqlplus system as sysdba" 

SQL*Plus: Release 12.2.0.1.0 Production on Wed May 27 15:11:08 2020

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Enter password: oracle

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> 
create user c##tester identified by test;
grant all privileges to c##tester;
exit
import oracle.jdbc.pool.OracleDataSource;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class OracleTest {

    @Test
    public void simpleTest() throws Exception {

        OracleDataSource ods = new OracleDataSource();
        ods.setDriverType("thin");
        ods.setUser("c##tester");
        ods.setPassword("test");
        ods.setServerName("localhost");
        ods.setPortNumber(1521);
        ods.setDatabaseName("ORCLCDB");
//        ods.setURL("jdbc:oracle:thin:c##tester/test@localhost:1521:ORCLCDB");

        try (Connection con = ods.getConnection();
             Statement stmt = con.createStatement();
             ResultSet rs = stmt.executeQuery("select sysdate as \"date\" from dual")) {
            while (rs.next()) {
                String date = rs.getString("date");
                System.out.println(date);
                Assertions.assertNotNull(date);
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment