X

The blog for hints & tips about Oracle Application Development Framework and Mobile Application Framework

  • ADFv
    February 28, 2012

Accessing WebLogic Server JDBC DataSource from Java in JSF

Frank Nimphius
Master Principal Product Manager

There may be a requirement
for you to access a JDBC data source defined on the WebLogic Server (for
example to query a database or database schema other than the one the application's
business service is connected with.

To access the JDBC DataSource,
for example from a managed bean in JSF, you code like the following:

java.sql.Connection
connection = null;

try {
 
javax.naming.Context initialContext = new javax.naming.InitialContext();
  javax.sql.DataSource dataSource =
          (javax.sql.DataSource)initialContext.lookup("java:comp/env/jdbc/hrconnDS");

  connection = dataSource.getConnection();
 

 } catch(Exception e){
      e.printStackTrace();
      //or handle more gracefully

 }
In
the example above, the JDBC DataSource is defined in WLS as "hrconnDS"

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.