Creative Solution: Server Side SQLJ in Oracle 12

Ash
2 min readMay 23, 2020

A couple of weeks ago i was working on a project linked to a database migration moving towards Oracle 12. I came across towards a feature in Oracle which i was not even aware that it exists. In Oracle, just like you have Tables, Procedures, Packages, you also have a functionality called Java, where you can create a complete java class in Oracle. How amazing is that!

I don’t know the intention behind that that functionality in Oracle but in our case, it was a Stored Procedure that was calling a Java Class and that Java Class was performing some operations that you cannot perform in a Stored Procedure.

Having said that, our problem that was in Oracle 12, the SQLJ is no longer supported. In the Java Class we had some SQL statements executed using the SQLJ.

For example:

#sql { TRUNCATE TABLE DIR_LIST };

If you compile the Java Class in the Oracle 12, you will receive a WARNING: Java Created with Compilation Errors.

As a quick fix, to solve the issue, we had to modify the Java Class in the form of the following statement:

For example, the statement above will become:

Connection conn = DriverManager.getConnection(“jdbc:default:connection:”);
PreparedStatement pstmt = conn.prepareStatement(“TRUNCATE TABLE DIR_LIST”);
pstmt.executeQuery();
pstmt.close();

Basically, what we were doing in one line using SQLJ, has now changed into a couple of lines, where we have to initiate a JDBC connection. Hope that helps!

--

--

Ash

Technical Dev Lead in Java Technologies, exploring the influence of software engineering.