We support many ways to connect in SQLcl, including lots from SQL*Plus which we need to support to make sure all your SQL*Plus scripts work exactly the same way using SQLcl as with SQL*Plus.

I've added several ways to show how to connect to SQLcl.  If there is one you want to see added that is not here, let me know and I'll add it to the list.  So far, We have below:
  • EZConnect
  • TWO_TASK
  • TNS_ADMIN
  • LDAP
At any time when connected you can use the command 'SHOW JDBC'  to display what the connection is and how we are connected.  Here's some details of the types above.

EZCONNECT

The easy connect naming method eliminates the need for service name lookup in the tnsnames.ora files for TCP/IP environments.  It extends the functionality of the host naming method by enabling clients to connect to a database server with an optional port and service name in addition to the host name of the database:

 $sql barry/oracle@localhost:1521/orcl  
 SQLcl: Release 4.1.0 Beta on Fri Feb 20 10:15:12 2015  
 Copyright (c) 1982, 2015, Oracle. All rights reserved.  
 Connected to:  
 Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production   
 SQL>   

TWO_TASK

The TWO_TASK (on UNIX) or LOCAL (on Windows) environment variable can be set to a connection identifier. This removes the need to explicitly enter the connection identifier whenever a connection  is made in SQL*Plus or SQL*Plus Instant Client. 

In SQLcl, we can set this up as a jdbc style connection like this


$export TWO_TASK=localhost:1521/orcl  




TNS_ADMIN


Local Naming resolves a net service name stored in a tnsnames.ora file stored on a client.  We can set the location of that in the TNS_ADMIN variable.

 $export TNS_ADMIN=~/admin  

An example tons entry is shown here below.

 $cat tnsnames.ora   
 BLOG =  
 (DESCRIPTION =  
 (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521) )  
 (CONNECT_DATA=  
 (SERVICE_NAME=orcl) ) )  

we can then use the entry to connect to the database.

 $sql barry/oracle@BLOG  
 SQLcl: Release 4.1.0 Beta on Fri Feb 20 10:29:14 2015  
 Copyright (c) 1982, 2015, Oracle. All rights reserved.  
 Connected to:  
 Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production   
 SQL>   

LDAP

We've already written about LDAP connections here.  Here's a quick review.

  set LDAPCON jdbc:oracle:thin:@ldap://scl58261.us.oracle.com:389/#ENTRY#,cn=OracleContext,dc=ldapcdc,dc=lcom   


 $export LDAPCON=jdbc:oracle:thin:@ldap://scl58261.us.oracle.com:389/#ENTRY#,cn=OracleContext,dc=ldapcdc,dc=lcom   
 $sql /nolog  
 SQLcl: Release 4.1.0 Beta on Fri Feb 20 10:37:02 2015  
 Copyright (c) 1982, 2015, Oracle. All rights reserved.  
 SQL> connect barry/oracle@orclservice_test(Emily's Desktop)   
 Connected  
 SQL>   

If we have more types to add, then they will appear here.  Let us know what you want to see.

10

View comments

  1. Try this in bash

    git p

    You get a file names p or a list of them.  Thats not much good, but there is a great bash completion library which you can source in your .bashrc to give you valid completion targets

    $git p
    pull
    push
    $git p


    Pull this file and source it in your .bashrc


    $wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
    $echo . $PWD/git-completion.bash >> ~/.bashrc


    Open up a new terminal window and enjoy.

    0

    Add a comment

  2. When a project has been on the go for a while theres going to be all sorts of stuff in there from jars to zips and everything in between.  We went though this a while ago and wanting to keep all the history, we needed a way to prune the history of all the big files and weird things we were not going to move to git.

    Now we knew we had some large files, namely binary files like jars which were build dependencies before we moved to artifactory for a lot of it.  So, before we start we need to make sure that git is installed, and git-lfs.  Git-lfs should be on the path so git can find it and you'll need to make sure git svn can run.  You'll need perl and  to run cpan (Comprehensive Perl Archive Network) to install the SVN::Core modules.

    Initialisation

    As a test to start, make sure git and git lfs are on the path and that git svn runs.

    bamcgill@bamcgill-mac[~
    - $ git --version
    git version 2.15.2 (Apple Git-101.1)
    bamcgill@bamcgill-mac[~
    - $ git lfs version
    git-lfs/2.3.4 (GitHub; darwin amd64; go 1.9.1)
    bamcgill@bamcgill-mac[~
    - $ git svn
    git-svn - bidirectional operations between a single Subversion tree and git
    usage: git svn [options] [arguments]

    Clone Empty GIT Repository

    Before the migration, we should create an empty repository for importing the subversion repository into.  Then we can clone it to start the migration

    git clone git@gitlab.yourcompany.com:group-name/gitrepo.git 
    
    

    Clone the subversion repository into the empty git repository

    Before we do the clone, we need to build a file of the authors on the svn

    svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt 

    Now we need to edit that file which has a format like this
    bamcgill = bamcgill
    to a format like this

    bamcgill = Barry McGillin

    This file is then used to map the users in subversion to the new decorated users in git.

    git svn clone https://server.company.com/svn/project/trunk gitrepo --authors-file=authors.txt > loglog 2>&1 
    
    
    We push the output into a log file because it takes ages and you can scroll back and see where the actual clone is.  This pulls the entire history from revision 1 to HEAD and drops it into the git repository

    Clean up the GIT Repository Metadata 

    Now, we use a really handy utility: BFG: Removes large or troublesome blobs like git-filter-branch does. For this exercise we run the utility twice. Once to strip blobs larger than 1M

    java -jar bfg-1.13.0.jar --strip-blobs-bigger-than 1M git-repo 
    
    
    Now fix the changes into the repository. 
    
    
    cd git-repo && git reflog expire --expire=now --all && git gc --prune=now --aggressive && cd - 
    
    
    Now for the second run of the BFG, we want to convert a bunch of things like binary files to Large File Storage

    java -jar bfg-1.13.0.jar --convert-to-git-lfs "*.{rar,dll,zip,war,gz,jar,tar,opar,dmp,serial,exe,mde,gif,msg,oxd_db,dylib,so}" --no-blob-protection git-repo 
    
    
    And fix that into the repository too.
    
    
    cd sql-developer && git reflog expire --expire=now --all && git gc --prune=now --aggressive && cd -  

    Install and Configure GIT LFS

    Create an file called .lfsconfig which has your preconfigured LFS server

    $cp lfsconfig git/.lfsconfig 
    $cat .lfsconfig
    [lfs]
     url = https://artifactory.yourcorp.com/api/lfs/git-lfs
     
    Now, you need to install lfs into the repository.

    cd git-repo && git lfs install 

    and then track all the binary and large files you want

    git lfs track *.{rar,dll,zip,war,gz,jar,tar,opar,dmp,serial,exe,mde,gif,msg,oxd_db,dylib,so}  

    Commit and Push

    Next we need to add the files we just edited AND the base directory of the git repository as all the binary files will be swapped out to LFS on push

    git add .lfsconfig .gitattributes && git add .

    git commit -m "initial commit to git" && git push origin master  

    Depending on the security setting of your artifactory repository you may be prompted for a username and password for pushing the binary files to LFS and then the references and files will be pushed to your remote git repository

    Summary

    It took us a couple of goes to get this right so we put it in a file to rerun when it died (it will til you get all the large file extensions listed)
    Heres the contents of that script you can grab and use for your migration.
    Have fun.

    git clone git@gitlab.yourcompany.com:group-dev/git-repo.git && \
    git svn clone https://svn.yourcompany.com/svn/project/trunk git-repo --authors-file=authors.txt > loglog 2>&1 && \
    java -jar bfg-1.13.0.jar --strip-blobs-bigger-than 1M git-repo && \
    cd git-repo && git reflog expire --expire=now --all && git gc --prune=now --aggressive && cd - && \
    java -jar bfg-1.13.0.jar --convert-to-git-lfs "*.{rar,dll,zip,war,gz,jar,tar,opar,dmp,serial,exe,mde,gif,msg,oxd_db,dylib,so}" --no-blob-protection git-repo && \
    cd git-repo && git reflog expire --expire=now --all && git gc --prune=now --aggressive && cd - && \
    cp lfsconfig git-repo/.lfsconfig && \
    cd git-repo && \
    git lfs install && \
    git lfs track *.{rar,dll,zip,war,gz,jar,tar,opar,dmp,serial,exe,mde,gif,msg,oxd_db,dylib,so} && \
    git add .lfsconfig .gitattributes && \
    git add . && \
    git commit -m "initial commit to git" && \

    git push origin master

    6

    View comments

  3. Getting Git installed in lots of places for a team can be a irksome.  Part of your team is running windows, maybe with Cygwin, others with various flavours on unix and osx.  Layered on top of that are the applications that we use with git services embedded in them.  This should serve as a sample page to show where we can get access to the clients and how we set them up for ssh which is our default.



    Installing git

    Overview of install at https://git-scm.com/book/en/v2/Getting-Started-Installing-Git.  Theres lots of different versions, but boiled up to basics are these below.

    Unix 

    • sudo yum install git-all
    • sudo dnf install git-all (RH)
    • sudo apt install git-all (debian)

    windows

    mac

    1. brew install git
    2. or download and install from http://git-scm.com/download/mac 

    Connections to GitHub

    We are specifically only looking at SSH connections so, heres some ways to get your keys sorted

    • generate an ssh key
    • add the public key to Orahub
    • Clone your repository

    SSH Key Generation

    Unix

    ssh-keygen -t rsa

    Windows

    Use Putty-gen . This is installed as part of the putty installation available here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

    Add your keys to GitHub or your Enterprise Git Repo

    In order to do this, its pretty specific.  You need to go to the your user settings page and click on ssh keys,  There, you can paste in your public key.  This will then let you clone your repositories with SSH as below.

    Clone Repository to local Repository

    unix terminal / cygwin 

    git clone git@orahub.oraclecorp.com/restofyourrepo.git destination

    tortoisegit




    sqldeveloper

    team â†’ Connect to git



    view â†’ files

    eclipse

    window â†’ perspective â†’ open perspective â†’ git repositories
    click clone git repository

    github desktop

    Download it from https://desktop.github.com/

    1

    View comments

  4. So, we're having a great time with git, fighting over how branches should work and what policy is best in our environment, which I suppose I'll talk about in another post, but for today, I wanted to share a little bit of usefulness.

    Most of our repositories have several branches for various releases and its often confusing and terse to 1. remember where you are and 2, run git branch to see.


    This for example, I have changed to my repository in GitHub, but unless you know that you're in a repository you couldn't be sure.  Long story short, lets say we've had one or two boo-boos along the way. 

    Now, imported projects in eclipse will have the branch of the code you're working on so today, we're going to bring it to the terminal.  Cut the following and put it in your .bashrc or .bash_profile and see your repository and branch pop out on the prompt.  Now,  I have decorated the prompt with some colours, which you might want to change.  (search for bash unix colors for details)

    parse_git_branch() {
         git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
    }

    parse_git_repo() {
         git rev-parse --show-toplevel 2> /dev/null | xargs basename| sed 's/\(.*\)/[\1]/'
    }

    export PS1="\[\033[91m\]\u\[\033[30m\]@\[\033[34m\]\h[\[\033[36m\]\w\[\033[30m\]] \
    \n\r\[\033[31m\]\$(parse_git_repo)\[\033[00m\]-\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

    What you get from all this, the next time you start a terminal is this (without my adornments).

    So, as soon as you enter a repository, the prompt now tells you which repository and which branch you are on too, in this case I have branch called flatten which I used for the previous post.  
    Finally, if you dont want the colour, strip the escape codes and while your PS1 export will look more sane, it'll lack a certain bedazzling...

    export PS1="\u@\h[\w] \n\r\$(parse_git_repo)-\$(parse_git_branch) $ "


    Have fun!
    1

    View comments

  5. We had the situation lately where we have a bunch of modules in a project and a common parent.  Now when we go to update the project version we need to update the parent version in EVERY pom.

    Lets take a look at a simple project

    This project has three simple modules which have a common parent

    1:  <project>  
    3:      <modelVersion>4.0.0</modelVersion>  
    4:      <packaging>pom</packaging>  
    5:      <name>Three Stooges</name>  
    6:      <groupId>oracle.blogger</groupId>  
    7:      <artifactId>stooges</artifactId>  
    8:      <version>1.0.0-SNAPSHOT</version>  
    9:      <properties>  
    10:          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    11:      </properties>  
    12:      <modules>  
    13:          <module>larry</module>  
    14:          <module>curley</module>  
    15:          <module>moe</module>  
    16:      </modules>  
    17:  </project>  
    

    Each module inherits from the parent including the version.  Lets take a look at Larrys module.

    1:  <project>  
    3:      <modelVersion>4.0.0</modelVersion>  
    4:      <packaging>jar</packaging>  
    5:      <name>Larry</name>  
    6:      <artifactId>larry</artifactId>  
    7:      <parent>  
    8:          <groupId>oracle.blogger</groupId>  
    9:          <artifactId>stooges</artifactId>  
    10:          <version>1.0.0-SNAPSHOT</version>  
    11:      </parent>  
    12:  </project>  
    

    In our larger project, we had over 20 of these to change at once when we branched for release

    Instead, we introduced a revision property in the parent pom, which was then used to be the version in all the pom's. Here's the modified parent pom with the revision in place.

    1:  <project>  
    3:       <modelVersion>4.0.0</modelVersion>  
    4:       <packaging>pom</packaging>  
    5:       <name>Three Stooges</name>  
    6:       <groupId>oracle.blogger</groupId>  
    7:       <artifactId>stooges</artifactId>  
    8:       <version>${revision}</version>  
    9:       <properties>  
    10:            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    11:            <flatten.version>1.0.1</flatten.version>  
    12:            <!-- Build Revision -->  
    13:            <revision>1.0.1-SNAPSHOT</revision>  
    14:       </properties>  
    15:       <modules>  
    16:            <module>larry</module>  
    17:            <module>curley</module>  
    18:            <module>moe</module>  
    19:       </modules>  
    

    and in each of the children, that change propagates like this.

    1:  <project>  
    2:       <modelVersion>4.0.0</modelVersion>  
    3:       <packaging>jar</packaging>  
    4:       <name>Larry</name>  
    5:       <artifactId>larry</artifactId>  
    6:       <parent>  
    7:            <groupId>oracle.blogger</groupId>  
    8:            <artifactId>stooges</artifactId>  
    9:            <version>${revision}</version>  
    10:       </parent>  
    11:  </project>  
    

    Now, for most things, this all works and we can see that in the build.


    But, when we deploy these builds to artifactory, we need to flatten the poms with the versions so that they can be used for versioning.  We can use the Maven Flatten Plugin from mojoHaus to help with this. What this does to the pom is:


  6. Run them with the code we use for Oracle SQL Developer, SQLcl and REST Data Services.
    We've just released some of the code that underpins these tools in an attempt to help  others run SQL, PLSQL and SQL*Plus scripts confidently and repeatably from java.

    From Github, look for the repository dbtools-commons. Look at my previous post to build it.

    The code below is one simple example to run sql code with the common jars we ship with sqlcl and sqldeveloper.

    Further down, I stuck in a pom file you can use to build with maven.

    Demo using Script executor to run SQL


    1:  import java.io.BufferedOutputStream;  
    2:  import java.io.ByteArrayOutputStream;  
    3:  import java.io.UnsupportedEncodingException;  
    4:  import java.sql.Connection;  
    5:  import java.sql.DriverManager;  
    6:  import java.sql.SQLException;  
    7:  import oracle.dbtools.db.ResultSetFormatter;  
    8:  import oracle.dbtools.raptor.newscriptrunner.ScriptExecutor;  
    9:  import oracle.dbtools.raptor.newscriptrunner.ScriptRunnerContext;  
    10:  /**  
    11:   * @author bamcgill  
    12:   */  
    13:  public class DemoScriptRunner {  
    14:    /**  
    15:     * @param args  
    16:     * @throws ClassNotFoundException  
    17:     * @throws SQLException  
    18:     * @throws UnsupportedEncodingException  
    19:     */  
    20:    public static void main(String[] args) throws ClassNotFoundException, SQLException, UnsupportedEncodingException {  
    21:      Class.forName("oracle.jdbc.driver.OracleDriver");  
    22:      Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/ORCL", "barry", "oracle");  
    23:      ScriptRunnerContext ctx = new ScriptRunnerContext();  
    24:      ctx.setBaseConnection(conn);  
    25:      ScriptExecutor executor = new ScriptExecutor(conn);  
    26:      ByteArrayOutputStream bout = new ByteArrayOutputStream();  
    27:      BufferedOutputStream bs = new BufferedOutputStream(bout);  
    28:      executor.setOut(bs);  
    29:      executor.setScriptRunnerContext(ctx);  
    30:      executor.setStmt("select * from all_objects where rownum < 10 ");  
    31:      ResultSetFormatter.setMaxRows(Integer.MAX_VALUE);  
    32:      executor.run();  
    33:      String results = bout.toString("UTF8");  
    34:      System.out.println(results);  
    35:    }  
    

    Pom File to build Code

    1:  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    2:      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
    3:      <modelVersion>4.0.0</modelVersion>  
    4:      <groupId>oracle.dbtools</groupId>  
    5:      <artifactId>demo-common</artifactId>  
    6:      <version>0.0.1-SNAPSHOT</version>  
    7:      <packaging>jar</packaging>  
    8:      <name>demo-common</name>  
    9:      <url>http://maven.apache.org</url>  
    10:      <properties>  
    11:          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    12:      </properties>  
    13:      <dependencies>  
    14:          <dependency>  
    15:              <groupId>junit</groupId>  
    16:              <artifactId>junit</artifactId>  
    17:              <version>3.8.1</version>  
    18:              <scope>test</scope>  
    19:          </dependency>  
    20:          <dependency>  
    21:              <groupId>oracle.dbtools</groupId>  
    22:              <artifactId>dbtools-common</artifactId>  
    23:              <version>LATEST</version>  
    24:          </dependency>  
    25:          <dependency>  
    26:              <groupId>com.oracle.jdbc</groupId>  
    27:              <artifactId>orai18n</artifactId>  
    28:              <version>12.2.0.1</version>  
    29:          </dependency>  
    30:          <dependency>  
    31:              <groupId>com.oracle.jdbc</groupId>  
    32:              <artifactId>orai18n-mapping</artifactId>  
    33:              <version>12.2.0.1</version>  
    34:          </dependency>  
    35:      </dependencies>  
    36:  </project>  
    


    1

    View comments


  7. Here we are again releasing Oracle SQLcl. We released Oracle SQLDeveloper SQLcl 18.1.1 yesterday with only one significant change.

    Why? Well, we haven't changed the SQLcl code in this release but we've made it easier for you to use the libraries we ship with it.  We've added a pom.xml into the lib directory.  On a day to day use of SQLcl, this will not affect your use of SQLcl, however, it will allow you to install the libraries we ship with SQLcl into your local maven repository.




    How does that work?  Well, you need to have maven installed in order to run the install.  You can check you have it like this.


    With confirmed you can run the install by invoking the command 'mvn validate' in the sqlcl/lib directory.

    which will take each jar and install it into your local maven repository.  By default, this will be ~/.m2


    While a lot of these jars are available in maven.oracle.com and maven.org, there are several that aren't.  We're working on getting our production jars published externally.  The ones we dont have published publicly yet are:

    low-level-api.jar                  ojdbc8.jar
    dbtools-common.jar                 oraclepki.jar
    dbtools-http.jar                   orai18n-mapping.jar
    dbtools-net.jar                    orai18n-utility.jar
    dbtools-sqlcl.jar                  orai18n.jar
    orajsoda.jar                       httpcore.jar                       
    osdt_cert.jar                      osdt_core.jar
    ucp.jar.                           jdbcrest.jar                
    xdb6.jar                           xmlparserv2-sans-jaxp-services.jar

    if you want to add these to your project, take the following dependency management and prune it for your needs.

    1:      <dependencyManagement>  
    2:          <dependencies>  
    3:              <dependency>  
    4:                  <groupId>com.oracle.jdbc</groupId>  
    5:                  <artifactId>ojdbc8</artifactId>  
    6:                  <version>12.2.0.1</version>  
    7:              </dependency>  
    8:              <dependency>  
    9:                  <groupId>oracle.soda</groupId>  
    10:                  <artifactId>orajsoda</artifactId>  
    11:                  <version>12.2.0.1.0</version>  
    12:              </dependency>  
    18:              <dependency>  
    19:                  <groupId>com.oracle.jdbc</groupId>  
    20:                  <artifactId>xdb6</artifactId>  
    21:                  <version>12.2.0.1</version>  
    22:              </dependency>  
    23:              <dependency>  
    24:                  <groupId>com.oracle.jdbc</groupId>  
    25:                  <artifactId>xmlparserv2-sans-jaxp-services</artifactId>  
    26:                  <version>12.2.0.1</version>  
    27:              </dependency>  
    28:              <dependency>  
    49:                  <groupId>com.oracle.jdbc</groupId>  
    50:                  <artifactId>orai18n</artifactId>  
    51:                  <version>12.2.0.1</version>  
    52:              </dependency>  
    53:              <dependency>  
    54:                  <groupId>com.oracle.jdbc</groupId>  
    55:                  <artifactId>orai18n-collation</artifactId>  
    56:                  <version>12.2.0.1</version>  
    57:              </dependency>  
    58:              <dependency>  
    59:                  <groupId>com.oracle.jdbc</groupId>  
    60:                  <artifactId>orai18n-mapping</artifactId>  
    61:                  <version>12.2.0.1</version>  
    62:              </dependency>  
    68:              <dependency>  
    69:                  <groupId>com.oracle.jdbc</groupId>  
    70:                  <artifactId>orai18n-utility</artifactId>  
    71:                  <version>12.2.0.1</version>  
    72:              </dependency>  
    710:              <dependency>  
    111:                  <groupId>oracle.dbtools</groupId>  
    112:                  <artifactId>dbtools-common</artifactId>  
    113:                  <version>18.1.1</version>  
    114:              </dependency>  
    115:              <dependency>  
    116:                  <groupId>oracle.dbtools</groupId>  
    117:                  <artifactId>dbtools-http</artifactId>  
    118:                  <version>18.1.1</version>  
    119:              </dependency>  
    120:              <dependency>  
    121:                  <groupId>oracle.dbtools</groupId>  
    122:                  <artifactId>dbtools-sqlcl</artifactId>  
    123:                  <version>18.1.1</version>  
    124:              </dependency>  
    125:              <dependency>  
    126:                  <groupId>oracle.dbtools</groupId>  
    127:                  <artifactId>jdbcrest</artifactId>  
    128:                  <version>18.1.1</version>  
    129:              </dependency>  
    130:              <dependency>  
    131:                  <groupId>com.oracle.jdbc</groupId>  
    132:                  <artifactId>osdt_cert</artifactId>  
    133:                  <version>12.2.0.1</version>  
    134:              </dependency>  
    135:              <dependency>  
    136:                  <groupId>com.oracle.jdbc</groupId>  
    137:                  <artifactId>osdt_core</artifactId>  
    138:                  <version>12.2.0.1</version>  
    139:              </dependency>  
    140:              <dependency>  
    141:                  <groupId>com.oracle.jdbc</groupId>  
    142:                  <artifactId>oraclepki</artifactId>  
    143:                  <version>12.2.0.1</version>  
    144:              </dependency>  
    160:              <dependency>  
    161:                  <groupId>oracle.cloudstorage</groupId>  
    162:                  <artifactId>low-level-api</artifactId>  
    163:                  <version>13.0.0</version>  
    164:              </dependency>  
    170:          </dependencies>  
    171:      </dependencyManagement>  
    

    Stay tuned, you'll have a project you can use this on soon!
    2

    View comments

  8. So you want Docker and to install and Oracle Database locally.  So did I and while I have VirtualBox and the Oracle Developer Day VM, I wanted to setup docker and the Oracle Database
    Well Colm Divilly (@cdivilly) has cleared it up for me.  His Gist on on Github had me up and running. Very little work on my part here, following Colm's detailed instructions, (barring time for downloads) I had docker up on mac in about 30 mins. 

    Take a look.....

    Download Database Binaries from Oracle Technology Network

    Download the linux x86-64 ZIP archive from here.

    Check out the Oracle Docker Images from Github

    There's a few ways to do this using an SVN or GIT client, but I just go to the project's home page, and click the button on the right hand side labeled 'Clone or Download' and then click 'Download Zip'.
    Next unzip this archive of the project that you just downloaded, for example:
    cd ~/work/docker
    unzip ~/Downloads/docker-images-master.zip
    

    Move the Database Binaries to the correct location

    To build the Docker image, you'll use a script named buildDockerImage.sh, for this script to work the Oracle Database binaries need to be placed in the correct location, for example:
    cd ~/work/docker/docker-images-master/OracleDatabase/
    mv ~/Downloads/linuxx64_12201_database.zip ./12.2.0.1
    
    This places the ZIP archive containing the Oracle Database binaries in the expected 12.2.0.1 sub-folder

    Configure the Proxy if necessary

    If you're behind a proxy, you'll need to ensure the http_proxy and https_proxy environment variables are set, so the proxy configuration can be propagated to the created Docker Container. If this is not done correctly then yum will not be able to reach any repositories.
    For example:
    export http_proxy=http://someproxy.corpdomain.com:80
    export https_proxy=http://someproxy.corpdomain.com:80
    

    Build the Docker Image

    To build the Docker image use the buildDockerImage.sh script, it's usage is described in the README. First let's ensure the script is executable:
    cd ~/work/docker/docker-images-master/OracleDatabase/
    chmod +x ./buildDockerImage.sh
    
    Next invoke the script to build the image, to build a 12.2.0.1 enterprise edition image:
    cd ~/work/docker/docker-images-master/OracleDatabase/
    ./buildDockerImage.sh -v 12.2.0.1 -e
    
    Go get a coffee, this step takes a while, for me it took about 16 minutes.

    Run the Docker Image

    When it comes to running the Docker Image, you have several choices to make, read the docs for more detail on this. I'm only going to change a few things:
    • set the name of the PDB created to ORCL
    • Store the database data on the host machine, this enables me to blow away the docker container at any time and re-create it without losing any data. In effect I'm separating the database 'engine' (the docker container) from the database storage (the volume on the host where the database storage is persisted).
    • Configure the Database to use Extended Data Types (increase max VARCHAR2 to 32767 bytes).

    Prepare the storage volume

    I created a folder within my home folder:
    cd ~/work/docker
    mkdir oradata
    
    Note the documentation states this folder must be owned by an operating system user named oracle. On my Mac OS host, I found I didn't need to create an oracle user or give it ownership of this folder.

    Extended Data Types

    In 12.1 and later VARCHAR2 fields can be configured to hold up to 32K bytes. However this feature is off by default, so we need to do some scripting to reconfigure the database to use extended data types. We want these scripts to run after the database is first setup, so we'll mount a volume as part of the docker run command which will cause those scripts to be executed.
    The script needed is attached to this gist, so first ensure you have downloaded this script into a folder. The easiest way to do this is to click the 'Download ZIP' button at the top right of this page and then unzip the downloaded archive into a folder, for example:
    cd ~/work/docker
    mkdir db_setup_scripts
    cd db_setup_scripts
    unzip -j ~/Downloads/8082bece*.zip 
    
    • We use the -j option to tell unzip not to bother recreating the directory structure of the archive
    We want to make sure any shell scripts are executable in the docker container, and remove unecessary files:
    cd ~/work/docker/db_setup_scripts
    chmod +x *.sh
    rm *.md
    

    Run the container

    Now we are all prepared, we can tell Docker to run the image, we'll give the container a name as well:
    docker run --name oracle -p 1521:1521 -e ORACLE_PDB=ORCL \
               -v ~/work/docker/oradata:/opt/oracle/oradata \
               -v ~/work/docker/db_setup_scripts:/opt/oracle/scripts/setup \
               oracle/database:12.2.0.1-ee
    
    • The -name argument names the container
    • The -e arguments passed an environment variable that renames the created PDB to ORCL (the default is ORCLPDB1)
    • The first -v argument mounts the folder to store the database data
    • The second -v argument mounts the folder containing the scripts to convert the database to use extended data types
    Time for another coffee, creating the initial database takes time. After a while the database will have been created, and the script to enable extended data types will have been executed

    Managing the Container

    Once the initial setup of the database has completed, I like to stop the container and then start it again to leave it running in the background. To do this, in another terminal do the following:
    docker stop oracle
    docker start oracle
    
    or simply:
    docker restart oracle
    

    Deleting the Container

    If you ever need to get rid of the container, then the following will remove the container, you can recreate it again using docker run:
    docker stop oracle
    docker rm oracle
    

    Connecting to the Database

    You can use the sqlplus as described in the docker images documentation but it's a bit hard to use because it can only read from the filesystem within the container. Much better to use it's more modern relative, SQLcl, which will run anywhere you can run Java, and doesn't require an Oracle Client install, so it's super easy to get working, and especially handy for Mac users.
    Since we have port forwarded the container's 1521 port to our host's 1521 port, we can use sqlcl to connect to the database as follows:

    Connect to the CDB

    To Connect to the CDB, just do the following:
    sql system
    
    SQLcl: Release 4.2.0.16.043.0306 RC on Fri Sep 08 18:10:52 2017
    
    Copyright (c) 1982, 2017, Oracle.  All rights reserved.
    
    Password? (**********?) ******
    Connected to:
    Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
    
    
    SQL> 
    

    Connect to the PDB

    To connect to the PDB, just do the following:
    sql system@//localhost:1521/orcl
    
    SQLcl: Release 4.2.0.16.043.0306 RC on Fri Sep 08 18:12:29 2017
    
    Copyright (c) 1982, 2017, Oracle.  All rights reserved.
    
    Password? (**********?) ******
    Connected to:
    Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
    
    
    SQL> 
    5

    View comments

  9. Oracle just released its first REST JDBC driver on OTN, in conjunction with the 17.3.0 Oracle REST Data Services Beta release.

    Dermot posted this morning about how to setup ORDS and Enable REST SQL Statements. The JDBC driver connects to this service and allows you to connect your JDBC based program to a REST services.

    As an example of this working with a standard application we can download the driver and drop it into Oracle SQLcl and connect to a service out of the box.



    • Unzip the sqlcl-17.2.0.184.1230-no-jre.zip





    •  and drop it into the SQLcl lib directory


    • Lastly start sqlcl with your appropriate URL, in my case is demo/demo@http:///ords//




    0

    Add a comment

  10. When you are restrained in the JRE that you can use with SQLcl, you can embed your own in the sqlcl directory tree.  We currently support 1.8 meaning that if you run with 1.7, you're going to have problems.
    When you look inside a sqlcl distribution, you will see the bin and lib directory. 
    Go grab a jre from somewhere, In my case, I'm getting it from my installed jdk

    Zip up the JRE and unzip it in the top level sqlcl directory.  You should have a structure like this now.

    Test what you have now by running SQLcl.  I'm doing a silent run to test it works for a start and also to check where the java is coming from. If you type 'show java' you'll get a lot of information about what is running and where it is.

    You can see here that the JRE from the installtion is being used so you can now drop this in another environment and run normally.

    0

    Add a comment

About Me
About Me
My Blog List
My Blog List
Subscribe
Subscribe
Blog Archive
Interesting Links
Loading
Dynamic Views theme. Theme images by Jason Morrow. Powered by Blogger.