Solved

Creating and Binding to e Context wih JAVA

Posted on 2006-11-14
4
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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