3.2 How To Tell If You Are Running on the Server

You may want to write Java code that runs in a certain way on the server and in another way on the client. In general, Oracle does not recommend this. In fact, JDBC enable you to write portable code that avoids this problem, even though the drivers used in the server and client are different.

If you want to determine if your code is running on the server, then you can use the System.getProperty ("oracle.jserver.version") method.

The getProperty() method returns the following information:

  • A String that represents Oracle Database release, if running on the server

  • null, if running on the client

The following code snippet shows how to determine if you are running your code on the server:

{
...
/*
  * This code snippet checks if you are
  * running your code on the server 
  */
        if (System.getProperty("oracle.jserver.version") != null)
        {
    		/*
    		   * Java running in the database, already connected, use the default
    		   * connection URL is ignored, assumed null
  	      */
      		
	      ods.setURL("jdbc:default:connection:");
        }
        else
        {
  	     /*
                  * Java not running in the database, you need a client URL
          */
	}
...
}