aspose file tools*
The moose likes BEA/Weblogic and the fly likes    how 2 access specific datasource using java code as per user requirement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "   how 2 access specific datasource using java code as per user requirement " Watch "   how 2 access specific datasource using java code as per user requirement " New topic
Author

how 2 access specific datasource using java code as per user requirement

viswanath edumudi
Greenhorn

Joined: Sep 14, 2010
Posts: 1
Hi WL users

we have one specific requirement like below.

we have 2 databases where one db is for uat & one for training. for each db, one datasource is available in weblogic console.

is their a way to access either of them using java coding as per user requirement?

kindly help.

Regards
vishy
Nir Tal
Greenhorn

Joined: Aug 31, 2010
Posts: 12
yes there is a way to access the JDBC datasource configured in weblogic using java code.. Suppose you have the UAT datasource as "projectUAT", then you have to code in java as :

String dataSourceName = "projectUAT";
javax.naming.Context ctx = new InitialContext();
javax.sql.DataSource ds = ctx.lookup(dataSourceName);
javax.sql.Connection conn = ds.getConnection();

//you can use the connection object as you like after this.

//you need to envelope this code snippet in proper try/catch block.
 
wood burning stoves
 
subject: how 2 access specific datasource using java code as per user requirement