Solved

Creating and Binding to e Context wih JAVA

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Programmatically send text messages 3 435
Java Uncaught Exception 5 232
JKS to store upstart data 2 85
Basics of Drool Rule Engine with few samples 2 56
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 article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

22 Experts available now in Live!

Get 1:1 Help Now