Updated 23 March 2023

SQLcl version 22.1 now has a minVer of 11 for Java. However, we ALSO support the other long term support release of Java, which is currently 17.

Java 11 support expires this September. In addition, Java 17 EE is free. For these two reasons, we recommend you use Java 17 for both ORDS and SQLcl.

However, if you are using Java 17, you may run into a problem if you want to use one of SQLcl’s most powerful features.

The #1 power (or advanced) feature for SQLcl, is the ability to run JavaScript. The examples I use to demonstrate this the frequently are:

For example in just a few lines of code…

Kris’ handy js library with examples.

No support for Nashorn in Java 17

What is Nashorn? It basically allowed for the JVM to also support running JavaScript. It’s much more than that, but end of day, it’s close.

The feature was deprecated in Java 11. It was completely removed in Java 15.

Since SQLcl ONLY supports Oracle Java 11 or 17 today, so you need to run 11 if you want to use the script command to work with js. Or do you…

I like both, but go with 11 if you want this feature.

What happens if you try with Java 17?

Boo!

How to fix it

You have two options:

  • GraalVM for Java 17 WITH the optional JavaScript Runtime Plugin
  • Downgrade to Java 11, yeah don’t do that

Now, why would we look at GraalVM?

Faster is always better, right?

Solution #1: GraalVM 17 with JavaScript Support

Download the appropriate GraalVM for your OS and Java Version.

I’ve picked 17 and Windows, and I simply copied the archive contents to my other GraalVM ‘homes’ –

Download, open zip, copy & paste.

Let’s see what happens if we DON’T grab the extra jar for JavaScript support.

It fails, as expected as Nashorn/JS support isn’t in base Java 17

So to fix this, download the Oracle GraalVM Enterprise Edition JavaScript Runtime Plugin.

These are the droids you’re looking for.

The download is a single JAR file.

Go to your GraalVM install and its bin directory.

Run this –

gu -L install js-installable-svm-svmee-java17-windows-amd64-22.3.1.jar
This only took a few seconds.

Now start SQLcl back up and let’s try running some JS again in SQLcl.

Bingo!

Using JAVA_HOME to tell SQLcl where to find Java

On Windows, the native EXE was previously setup read the Windows Registry to look for Java. It made switching between versions of Java on Windows painful.

IF you use a Windows Installer to put down Java 11/17, it should setup your Windows machine to use it by default, and SQLcl will be impacted by that.

But for any version of SQLcl 22.1 and higher, you can now simply set JAVA_HOME to the Java Home you want the sql.exe to use, and you’re good. Turloch, if you’re reading this, we all say, ‘Thank you!’

c:\>set JAVA_HOME=C:\1-GraalVM\graalvm-ee-java17-22.3.1

c:\>echo %JAVA_HOME%
C:\1-GraalVM\graalvm-ee-java17-22.3.1
Author

I'm a Distinguished Product Manager at Oracle. My mission is to help you and your company be more efficient with our database tools.

7 Comments

  1. Hello,

    Do you thing it might be possible that sqlcl would come compiled with GraalVM?

    Regards,
    Jean

  2. @leor, Good news. GraalVM now supports version 17.

    While SQL Developer does not officially support Java 17, it still works there too. Me like!

Reply To leor Cancel Reply