This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic