jQuery in Action, 2nd edition*
The moose likes Websphere and the fly likes Initial Context problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Initial Context problem" Watch "Initial Context problem" New topic
Author

Initial Context problem

Shireen Loke
Greenhorn

Joined: Jan 05, 2002
Posts: 12
Dear experts,
I have succesfully compile my program, but when I run it, the program just stop there with no response until I press <ctrl><C>.
I know exactly which line cause the problem. It is
this line "javax.naming.Context context = new javax.naming.InitialContext(parms);" that cause this problem.
The datasource and resource have been properly set up in WebSphere. For your information,the following is my .java
______________
import javax.sql.DataSource;
import javax.naming.*;
import com.ibm.ejs.ns.jndi.*;
import java.sql.*;
import java.util.*;import com.ibm.websphere.advanced.cm.factory.*;

public class DataBean
{
private final String DATASOURCE = "Minnie";
public Connection getConnection()
{
Connection conn = null;
DataSource ds = null;
try
{
java.util.Properties parms = new java.util.Properties();
parms.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
javax.naming.Context context = new javax.naming.InitialContext(parms);
ds = (DataSource)context.lookup(DATASOURCE);
conn = ds.getConnection("aaa","aaa");
}
catch (Exception t)
{
// DataSource not found. Throw Exception
}
finally {
return conn;
}
}
}
______________

Is there anything that I have to do to make it work. It seems normal with the javax.naming.*
Shireen
Alagan Devika
Greenhorn

Joined: Jan 04, 2002
Posts: 17
Hi,
Add this code
parms.put(javax.naming.Context.PROVIDER_URL, "iiop://");
As you never gave the Providerurl the error occurs.
Hope this helps.
Shanthi
Shireen Loke
Greenhorn

Joined: Jan 05, 2002
Posts: 12
It didn't work. According to the infomation provided (IBM Webpage), it seems ok not to submit the provider_url. Could it be the WebSphere setting that leads to this problem? Anything specific that I need to set besides the resource and datasource?
Alagan Devika
Greenhorn

Joined: Jan 04, 2002
Posts: 17
Which Database is used in your application?
DB2 or oracle?
If it is oracle, in the datasource, "jdbc/Minnie" is preferred.
Shanthi
Shireen Loke
Greenhorn

Joined: Jan 05, 2002
Posts: 12
Shanti,
I am using PostgreSQL.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
Actually a naming context of "jdbc/SOMENAME" is always preferred regardless of the database.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Initial Context problem
 
Similar Threads
Cannot find method compilation error
InitialContext WebSphere 3.5.4
Content.INITIAL_CONTEXT_FACTORY
mysql connectivity with jboss
WebSphere - DB2 DataSource Connection Problem