How check the jdbc client version in your database?

On the java side you can check the JDBC Client Version very easy.

java -jar ./mwhome/.../ojdbc7.jar -getversion
Oracle 12.1.0.2.0 JDBC 4.1 compiled with JDK7 on Mon_Jun_30_11:30:34_PDT_2014
#Default Connection Properties Resource
#Tue Apr 17 14:13:51 CEST 2018

But somethimes you may not have access to the application server (here Weblogic) or there are many version installed on the application side.
So the best way is to check in you Oracle Database who your client are.

SQL> select SID,NETWORK_SERVICE_BANNER,CLIENT_CHARSET,CLIENT_CONNECTION,CLIENT_VERSION,CLIENT_DRIVER from v$session_connect_info;
       396
Crypto-checksumming service for Linux: Version 12.2.0.1.0 - Production
Unknown                                  Heterogeneous 12.1.0.2.0                               jdbcthin

This is a reliable way to find how (jdbcthin, oci, ..) and with what JDBC Version the client are connecting.

java.lang.ArrayIndexOutOfBoundsException without stack trace

Recently I got across a java.lang.ArrayIndexOutOfBoundsException, but could not find any stack trace. So it was difficult to find where the Exception was thrown.
The “problem” was the OmitStackTraceInFastThrow JVM option which is set by default for performance reasons.

It can be disabled with this JVM option:

-XX:-OmitStackTraceInFastThrow

After that you get a regular stack trace an can find the problem.
The best solution seems to be to avoid the ArrayIndexOutOfBoundsException by proper coding, so if the exception is not thrown at all there should be no performance impact.

How to use Apache Thrift with Google App Engine

I’m on holiday an played around with some stuff I want to learn. So I came across the question: “Can I use Thrift with the Google App Engine”.  I could not find clear answers nor useful examples. That’s why I decided to test it.

Short answer: yes, you can!

The full story:

The Google App Engine is great to run simple Servlets. But it has many limitations. One limitation is that you can not use any outbound connection on any port (on the experimental Managed VM are more option available). But most Thrift tutorials use a TSocketServer with a specific port. This seem not to work on the GAE.

But… a thrift server can be implemented very easy as Servlet.

import org.apache.thrift.server.TServlet;
import org.apache.thrift.protocol.TCompactProtocol;

public class SearchServlet extends TServlet {

public SearchServlet() {
  super(new SearchEanService.Processor<>(new SearchEanHandler()), new TCompactProtocol.Factory());
}

My example interface has just one function “string search(string abc)”.

import org.apache.thrift.TException;

public class SearchEanHandler implements SearchEanService.Iface {
    public void ping() throws TException {
    }
    public String search(String ean) throws TException {
        return "found the fish";
    }
}

The client uses THttpClient and looks like this.

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.THttpClient;

public class GameExClient  {
    private void invoke() {
        THttpClient transport;
        try {
            transport  = new THttpClient("http://localhost:8080/search");
            TProtocol protocol = new TCompactProtocol(transport);

            SearchEanService.Client client = new SearchEanService.Client(protocol);
            transport.open();

            String result = client.search("search it");
            System.out.println("Add result: " + result);

            transport.close();
        } catch (TTransportException e) {
            e.printStackTrace();
        } catch (TException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        GameExClient c = new GameExClient();
        c.invoke();

    }
}

So we need not separate port. The thrift client just connects over the regular port with the servlet context path.

Let’s try it.
Start the local Google App Engine

mvn3 appengine:devserver

And start the client. (yes, I know it looks a bit ugly, but the demo was just created with maven and vim)

java -cp ".:../lib/libthrift-0.9.3.jar:../lib/slf4j-api-1.7.12.jar:../lib/httpclient-4.4.1.jar:../lib/httpcore-4.4.4.jar" ch/rcms/gameex/GameExClient
Add result: found the fish

Voila and it works.
So lets forget about heavy REST / JSON implementations do it with thrift 🙂