How Do You Test a Remote Oracle Database Connection (with Credentials You Were Given) from a Linux Command Prompt?

Problem scenario
You have no desktop GUI and a limited ability to install new applications other than the Java compiler.  You are not be allowed to install a SQL command line client such as sqlconnect or a utility such as tnsping.  What should you do to test the credentials, server name and port number to ensure they work to allow access to an Oracle database?

The overview is to use a Java program with the code provided below.

You need to be able to compile Java programs.  The "javac" command must be recognized.  To do this install a Java compiler.  If you do have this and do not know how, see this posting.

1.  Find the jre/lib/ext directory path on your server.  (e.g., sudo find / -name ext -type d | grep lib). 

2.  Place an ojdbc14.jar file (e.g., downloaded from or some trustworthy website) in that directory above. Here is one place to get it.

3.  From any directory create a program such as this called

    import java.sql.*;  //first line of file
    class OracleCon{  
    public static void main(String args[]){  
    //step1 load the driver class  

    //step2 create  the connection object  
    Connection con=DriverManager.getConnection(  

    //step3 create the statement object  
    Statement stmt=con.createStatement();  

    //step4 execute query  
    ResultSet rs=stmt.executeQuery("select * from all_users");  
    System.out.println(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  

    //step5 close the connection object  

    }catch(Exception e){ System.out.println(e);}  

    }  // last line of file

(This code was largely taken from

In the above code, you need to make some modifications:

  • Replace "jdoe" with the Oracle SQL user, and replace "strongPassword" with jdoe's password. 
  • Replace "contintserver" with the servername of the remote Oracle server.
  • Replace "xe" with the SID.  You may need to ask the DBA for this SID as it can be crucial. 
  • Under the comment "//step4 execute query" there is a SELECT statement in quotes. You can change this SQL command, but it often works as a test.

4.  To compile it, use javac

5.  To run the compiled byte code, run java OracleCon without quotes.  The output of running this Java program should give you an indication of whether or not the credentials work to connect to the database.

As a closing tip, we have seen a source (an article,, published in June of 2015) indicated that the two forward slashes "//" are a necessary constructor for a JDBC connection string.  We know in 2018 that this is not necessary in all instances.

Leave a comment

Your email address will not be published. Required fields are marked *