Solved

Creating and Binding to e Context wih JAVA

Posted on 2006-11-14
4
513 Views
Last Modified: 2013-12-10
Hello
I am trying to look up a Datasource  and am getting an error. Here is my code

  cnt = new InitialContext();
  sqlData = new SQLServerConnectionPoolDataSource();
  sqlData = (SQLServerConnectionPoolDataSource)cnt.lookup("vccon");

I ma getting a null exception

I created the the connection pool an dthe datasource in Weblogic so I shouldn't have to use specify the connection factory properties with a hash table.

But just to be on the safe side a tried that as well and here is my code for that

 hash = new Hashtable();
 hash.put(cnt.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
 hash.put(cnt.PROVIDER_URL,"t3://localhost:7001");
 cnt = new InitialContext(hash);

I am also getting a null exception
I have no idea what else to do

Please advise!!
0
Comment
Question by:rnzimiro
  • 2
4 Comments
 

Author Comment

by:rnzimiro
ID: 17939954
I am uising WebLogic 8.1
0
 
LVL 10

Expert Comment

by:ECollin
ID: 17945223
Hi

you need to specify jndi connection properties when your code is executed outside the weblogic'jvm. For instance, a standalone java application need to get a connection to a database through a datasource hosted in a weblogic server.

the line : sqlData = new SQLServerConnectionPoolDataSource(); is not required. You will get the instance with the lookup.
Are you sur to use the good jndi name for the datasource ?

Can you give us a stack trace plz ?

Emmanuel
0
 
LVL 6

Accepted Solution

by:
Ajar earned 500 total points
ID: 17948667
Check for weather the data source object actually exists with following code

 cnt = new InitialContext();
 
Object o  = cnt.lookup("vccon");
if(o != null){
System.out.println("SUCCESS lookup");
}else{
System.out.println("FAILURE lookup");
// THis means that the datasource object is not bound to jndi tree
throw new Exception("Failed to lookup vccon");
}

javax.sql.DataSource ds = (javax.sql.DataSource ) o;
java.sql.Connection = ds.getConnection();
...
....
The rest of sql code comes here
---




0
 

Author Comment

by:rnzimiro
ID: 17952109
I got it to work.  Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now