Bypassing the Listener and Connecting the Instance without a Password from Java Code


In the past I wrote a post about Bypassing the listener and connecting to ASM without a password from Python code

Now, I've been asked to prove that it can be done in Java. The solution is almost the same.

Java sample code using OCI:

$ vi OracleCon.java
import java.sql.*;
class OracleCon {
    public static void main(String args[]) {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection(
                "jdbc:oracle:oci:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL=BEQ) (PROGRAM=oracle) (ARGV0=oracle+ASM) (ARGS='(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))') (ENVS = 'ORACLE_HOME=/oracle/product/12.1.0.2/grid,ORACLE_SID=+ASM'))) (CONNECT_DATA= (SID=+ASM)))", "sys as sysdba", "change on install");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select * from v$instance");
            while (rs.next())
                System.out.println(rs.getInt(1) + "  " + rs.getString(2) + "  " + rs.getString(3));
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

I used Java for Oracle software (1.6):

$ export PATH=$ORACLE_HOME/jdk/jre/bin:$ORACLE_HOME/jdk/bin:$PATH
$ export CLASSPATH=.:$ORACLE_HOME/jdbc/lib/ojdbc6.jar
$ javac OracleCon.java
$ java OracleCon
1  +ASM  myhost
Yep... it is working  :)
Yossi

Comments

Popular posts from this blog

Silent Installation

Data Guard - Changing IP Addresses

Fixing & Registering ORACLE_HOMES in Central Inventory