Solved

Creating and Binding to e Context wih JAVA

Posted on 2006-11-14
4
516 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Exception thrown while starting tomcat on Mac OS 7 90
ColdFusion Application log reports a 'Java heap space' error 6 318
oneTwo java challenge 31 622
zip zap java cchallenge 3 112
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 shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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