I needed to access a data source remotely on FMW 11g server from JDeveloper 11g. I found that to do this I needed to follow these steps.
Note: This was done using 11.1.1.2 which is the latest version of FMW 11g and JDeveloper 11g1. Edit setDomainEnv script to ensure you set this property to true. By default it's false.
WLS_JDBC_REMOTE_ENABLED="-Dweblogic.jdbc.remoteEnabled=true"2. Re-start your server to pick up the change done at step #1 above.
3. In your project add the following libraries to allow remote access and the required JDBC driver library.
- Weblogic 10.3 Remote-Client
- Oracle JDBC
4. From JDeveloper access your data source remotely with code as follows making sure you use your connection details and the correct JNDI name for the data source.
package pas.au.remote.wls11g;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class RemoteDataSourceAccess
{
private Logger logger = Logger.getLogger(this.getClass().getSimpleName());
public RemoteDataSourceAccess()
{
}
public void run ()
{
logger.log(Level.INFO, "Started RemoteDataSourceAccess at " + new Date());
InitialContext ctx = null;
try
{
ctx = getInitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/scottDS");
Connection conn = (Connection) ds.getConnection();
logger.log(Level.INFO, "Got connection : " + conn);
logger.log(Level.INFO, "Auto Commit = " + conn.getAutoCommit());
}
catch (NamingException e)
{
logger.log(Level.SEVERE, "Error occurred", e);
System.exit(1);
}
catch (SQLException e)
{
logger.log(Level.SEVERE, "SQLException occurred", e);
System.exit(1);
}
logger.log(Level.INFO, "Ended RemoteDataSourceAccess at " + new Date());
}
public static InitialContext getInitialContext() throws NamingException
{
String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
String url = "t3://wayne-p2.au.oracle.com:7003";
String username = "weblogic";
String password = "welcome1";
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
return new InitialContext(env);
}
public static void main(String[] args)
{
RemoteDataSourceAccess test = new RemoteDataSourceAccess();
test.run();
}
}
5. Output as follows.
25/02/2010 9:22:56 AM pas.au.remote.wls11g.RemoteDataSourceAccess runINFO: Started RemoteDataSourceAccess at Thu Feb 25 09:22:56 EST 201025/02/2010 9:23:03 AM pas.au.remote.wls11g.RemoteDataSourceAccess runINFO: Got connection : weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1032_WLStub@125/02/2010 9:23:03 AM pas.au.remote.wls11g.RemoteDataSourceAccess runINFO: Auto Commit = true25/02/2010 9:23:03 AM pas.au.remote.wls11g.RemoteDataSourceAccess runINFO: Ended RemoteDataSourceAccess at Thu Feb 25 09:23:03 EST 2010