Tuesday, 27 September 2011

Get connection to APPS schema without knowing APPS password in EBS

 

First of all I need to explain that this post will not explain how to get the APPS password , but will explain how to obtain JDBC connection object.

   Each one who ever developed Oracle Framework page knows that you don’t really need to specify APPS password to work with EBS. But you do need to specify location of dbc file. Why? Because there is an option to get “Connection” object by using dbc file.

   First of all how do you know what dbc file to use?

dbc name can be obtained from the profile called  “Applications Database ID” (APPS_DATABASE_ID). You can get it from EBS  profile directly or by using:

select fnd_profile.VALUE('APPS_DATABASE_ID') from dual

Lets call the value of profile DBC_VALUE.

So , the location of dbc file will be $FND_SECURE/DBC_VALUE.dbc

Now , when you know the location of dbc file we can obtain JDBC connection.

We will use the following code:

 

import java.sql.*;

//this classes located under $OA_JAVA in EBS
import oracle.apps.fnd.common.AppsContext;
import oracle.apps.fnd.common.VersionInfo;

public class GetConnection
{
public GetConnection(String dbcFileLocation)
{
AppsContext ac
= new AppsContext(pDbcFile);
Connection sConn
= ac.getJDBCConnection();
}
//do whatever you want after you get Connection
}

The connection object that you get connected to , is APPS user. From this point you can do whatever operation with database that APPS user is privileged to do

Sunday, 5 June 2011

Solving java.lang.InstantiationException exception when running Java Concurrent Program

 

Assume that you want to create new Java Concurrent Program , but you also want to be able to execute this class as a standalone class with “main” method. Here is an example of such a class
public class SampleJavaConcProg implements JavaConcurrentProgram{

private Connection _conn;

public SampleJavaConcProg(Connection conn)
{
_conn
= conn;
}
public void runProgram(CpContext cp)
{
_conn
= cp.getJDBCConnection();

}
public static void main(String [] param) throws SQLException
{
DriverManager.registerDriver(
new OracleDriver());
String connectionString
= param[0];
Connection connection
= DriverManager.getConnection(connectionString,"SCOTT","TIGER");

SampleJavaConcProg prog
= new SampleJavaConcProg(connection);
}
}
You can see that this class can initialize Connection object by using CpContex object that is provided to you by Java Concurrent Program in EBS or directly by “main” method. But!!! If you try to run this class as a concurrent you will get the following error.

java.lang.InstantiationException: xxx.xxx.xxx.xxx.xxxx.SampleJavaConcProg at java.lang.Class.newInstance0(Class.java:335) at java.lang.Class.newInstance(Class.java:303) at oracle.apps.fnd.cp.request.Run.main(Run.java:152)


It doesn’t work. What is the reson? Don’t know, but I do know how to solve it. Just create a default constructor in your class.

Modified code will look like
public class SampleJavaConcProg implements JavaConcurrentProgram{

private Connection _conn;

//default constractor
public SampleJavaConcProg()
{

}
public SampleJavaConcProg(Connection conn)
{
_conn
= conn;
}
public void runProgram(CpContext cp)
{
_conn
= cp.getJDBCConnection();

}
public static void main(String [] param) throws SQLException
{
DriverManager.registerDriver(
new OracleDriver());
String connectionString
= param[0];
Connection connection
= DriverManager.getConnection(connectionString,"SCOTT","TIGER");

SampleJavaConcProg prog
= new SampleJavaConcProg(connection);
}
}
No more error messages…..