Apache DBCP and Oracle Transparent Application continuity

88 views Asked by At

We have an older application that can't failover when one node of our Oracle RAC goes down. It seems it uses an older version of org.apache.commons.dbcp.BasicDataSource. I can make this work when I use UCP from Oracle but when I use the apache version the app dies as soon as I shut down the node of the RAC it is connected to. Am I missing something or does it not work with Apache DBCP? Thanks

Here is my code.

import org.apache.commons.dbcp.BasicDataSource;

import java.io.PrintStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class BasicDB{



    final static String DB_URL ="jdbc:oracle:thin:user/password@pdb_tac";
    final static String driverClassName = "oracle.jdbc.replay.OracleDataSourceImpl";

    private void pressAnyKeyToContinue()
    {
        System.out.print("Press any key to continue...");
        try { System.in.read(); }
        catch(Exception e) { e.printStackTrace(); }
    }
    public String getInstanceName(Connection conn) throws SQLException {
        PreparedStatement pstmt = conn.prepareStatement("select instance_name from v$instance");
        String r = new String();

        for(ResultSet result = pstmt.executeQuery(); result.next(); r = result.getString("instance_name")) {
        }

        pstmt.close();
        return r;
    }



    private void doTx(Connection c, int numValue) throws SQLException {
        String updsql = "UPDATE test SET v=UPPER(v) WHERE id=?";
        PreparedStatement pstmt = null;
        pstmt = c.prepareStatement(updsql);
        c.setAutoCommit(false);

        for(int i = 0; i < numValue; ++i) {
            pstmt.setInt(1, i);
            pstmt.executeUpdate();
        }

        c.commit();
        pstmt.close();
    }

    public static void main(String[] args) throws SQLException {
        Connection conn = null;
        int numValue = 5000;
;

        try {

            BasicDataSource bods = new BasicDataSource();
            bods.setUrl(DB_URL);
            bods.setDriverClassName(driverClassName);
            bods.setDefaultAutoCommit(false);
            BasicDB self = new BasicDB();
            conn = bods.getConnection();
            String var10001 = self.getInstanceName(conn);
            var10000.println("Instance Name = " + var10001);
            System.out.println("Performing transactions");
            self.pressAnyKeyToContinue();
            self.doTx(conn, numValue);
            var10001 = self.getInstanceName(conn);
            var10000.println("Instance Name = " + var10001);

        } catch (Exception var8) {
            var8.printStackTrace();
        }

    }
}
1

There are 1 answers

0
cptkirkh On

Ok, so it has to do with using the DataSource instead of the DataDriver class. I have run into another error so will create a new question for that.