• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Initial Context problem

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shanti,
I am using PostgreSQL.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually a naming context of "jdbc/SOMENAME" is always preferred regardless of the database.
Kyle
reply
    Bookmark Topic Watch Topic
  • New Topic