Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
viswanath edumudi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic