Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating and Binding to e Context wih JAVA

Posted on 2006-11-14
4
Medium Priority
?
524 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 1500 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

971 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