Connecting to a database with SQLcl

In the last post I covered downloading and running SQLcl, now let’s try and connect to a database.

I have an Oracle XE database running on my local machine, so lets try and just enter the username and password of a valid schema to connect to that.


bash-3.2$ ./sql

SQLcl: Release 4.1.0 Release Candidate on Tue Jun 14 19:42:12 2016</span>

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

Username? (''?) jes
Password? (**********?) **********
USER = pre3_prod
URL = jdbc:oracle:thin:@localhost:1521/orcl
Error Message = IO Error: The Network Adapter could not establish the connection

ok, so that didn’t work…

The issue here is that it defaults to localhost and port 1521 (which is where my instance is running), but the service name it defaults to (orcl) isn’t valid.

Ok, so let’s try again this time passing the correct parameters


bash-3.2$ ./sql

SQLcl: Release 4.1.0 Release Candidate on Tue Jun 14 19:42:12 2016
 
Copyright (c) 1982,2016, Oracle. All rights reserved.

Username? (''?) jes@localhost:1521/xe
Password? (**********?) **********
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL>

Great, success!

Actually SQLcl supports a number of different options when it comes to connection strings, namely –

  • jdbc:oracle:thin
  • jdbc:oracle:oci8
  • jdbc:oracle:kprb
  • jdbc:default:connection
  • jdbc:oracle:kprb:
  • jdbc:default:connection:

So now we’re connected let’s explore the available commands using the help command


SQL> help
For help on a topic type help <topic>
List of Help topics available:
/ @ @@ ACCEPT ALIAS APEX
ARCHIVE_LOG BREAK BRIDGE BTITLE CD CHANGE
COLUMN COMPUTE CONNECT COPY CTAS DDL
DEL DESCRIBE DISCONNECT EDIT EXECUTE EXIT
GET HISTORY HOST INFORMATION INPUT LIST
NET OERR PASSWORD PAUSE PRINT PROMPT
REMARK REPEAT RESERVED_WORDS REST RUN SAVE
SET SHOW SHUTDOWN SODA SPOOL SSHTUNNEL
STARTUP STORE TIMING TNSPING TTITLE UNDEFINE

this hasn’t formatted very well in this code editor, but here’s a screenshot

In the next post, we’ll explore the ALIAS command.

2 thoughts on “Connecting to a database with SQLcl

  1. Pingback: SQLcl – Using Aliases | Johns Blog

  2. Pingback: SQLcl – do REPEAT yourself | Johns Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s