Board index » jbuilder » Re: WAS 4.0 JDBC/JNDI problem

Re: WAS 4.0 JDBC/JNDI problem


2004-08-25 04:17:39 PM
jbuilder17
"Patrick Wong" < XXXX@XXXXX.COM >wrote in message
Quote
public DB() {
try{
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/TestDataSource");
if(conn == null)
conn = new DBConnectionPool(sDBDriver, sConnStr, userid, passwd,
3,
6);
}
catch(Exception ex){
ex.printStackTrace();
errorMessage = ex.getMessage();
}
}

I explored more online resources and found that the code fragment applied to
WebSphere AppServer (WAS) 3.5 only. With WAS 4.0 which I am running the
code should be changed as:
javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/TestDataSource");
After this modification, the exception became:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context
"java:".
No idea on what that means. Any advice is greatly appreciated.
Patrick
 
 

Re:Re: WAS 4.0 JDBC/JNDI problem

"Patrick Wong" < XXXX@XXXXX.COM >wrote in message
Quote

"Patrick Wong" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>public DB() {
>try{
>Context ctx = new InitialContext();
>DataSource ds = (DataSource)ctx.lookup("jdbc/TestDataSource");
>if(conn == null)
>conn = new DBConnectionPool(sDBDriver, sConnStr, userid, passwd,
3,
>6);
>}
>catch(Exception ex){
>ex.printStackTrace();
>errorMessage = ex.getMessage();
>}
>}
>
I explored more online resources and found that the code fragment applied
to
WebSphere AppServer (WAS) 3.5 only. With WAS 4.0 which I am running the
code should be changed as:

javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/TestDataSource");

After this modification, the exception became:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in
context
"java:".

No idea on what that means. Any advice is greatly appreciated.
Patrick
What that means in that java: was found via jndi, but the rest was not.
I hope this will help you.
publib.boulder.ibm.com/infocenter/ws51help/index.jsp
Watch for wrap.
Mike
 

Re:Re: WAS 4.0 JDBC/JNDI problem

Patrick Wong wrote:
Quote
I explored more online resources and found that the code fragment applied to
WebSphere AppServer (WAS) 3.5 only. With WAS 4.0 which I am running the
code should be changed as:

javax.sql.DataSource ds =
(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/TestDataSource");

After this modification, the exception became:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context
"java:".

No idea on what that means. Any advice is greatly appreciated.
Patrick


Patrick, I had a similar problem on WebLogic. The naming was different,
depending on EAR vs WAR deployment. I discovered this by writing a
little jsp page that allowed me to poke around in the JNDI tree.
I've posted that jsp file in the borland.public.attachments group, with
the subject jnditest.jsp.
Try deploying that jsp file to WAS, and see what you can find. If you
can't find your data source, then it hasn't been deployed/configured
properly. If you can find it, then you should know exactly what the
context lookup string is called.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

{smallsort}

Re:Re: WAS 4.0 JDBC/JNDI problem

"Lori M Olson [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote

Try deploying that jsp file to WAS, and see what you can find. If you
can't find your data source, then it hasn't been deployed/configured
properly. If you can find it, then you should know exactly what the
context lookup string is called.

I don't know whether I deployed the JSP properly, the JSP read:
JNDI Names
comp: com.ibm.ws.naming.java.javaURLContext
JNDI Bindings comp:
com.ibm.ws.naming.java.javaURLContext:com.ibm.ws.naming.java.javaURLContext(
java:comp)
"java:" was inside the edit input.
That means the configuration is correct or not?
Thanks,
Patrick
 

Re:Re: WAS 4.0 JDBC/JNDI problem

Patrick Wong wrote:
Quote

I don't know whether I deployed the JSP properly, the JSP read:

JNDI Names
comp: com.ibm.ws.naming.java.javaURLContext

JNDI Bindings comp:
com.ibm.ws.naming.java.javaURLContext:com.ibm.ws.naming.java.javaURLContext(
java:comp)

"java:" was inside the edit input.

That means the configuration is correct or not?

Thanks,
Patrick


Sorry. It was just a little test page. Guess I should have written up
an explanation of how to use it ;-)
The "java:" in the edit box is the context you are looking at.
Then the page displays the naming contexts which are accessible under
"java:" and the objects that are bound at that level.
The next step is to enter "java:comp" in the edit box (since you can see
that "comp" exists under "java:"), and then Submit to see what exists
under that context. You can keep doing this until you've explored the
entire naming context.
Hopefully you will find your data source under there somewhere.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Re: WAS 4.0 JDBC/JNDI problem

"Lori M Olson [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote

Sorry. It was just a little test page. Guess I should have written up
an explanation of how to use it ;-)

Thanks for your kind advice and patience.
Quote

The next step is to enter "java:comp" in the edit box (since you can see
that "comp" exists under "java:"), and then Submit to see what exists
under that context. You can keep doing this until you've explored the
entire naming context.

After the first iteration, i.e. entering "java:comp" in the edit box, the
JSP read:
JNDI Names
env: com.ibm.ws.naming.java.javaURLContext
UserTransaction: com.ibm.ejs.jts.jta.UserTransactionImpl
JNDI Bindings
env:
com.ibm.ws.naming.java.javaURLContext:com.ibm.ws.naming.java.javaURLContext(
java:comp/env)
UserTransaction:
com.ibm.ejs.jts.jta.UserTransactionImpl:com.ibm.ejs.jts.jta.UserTransactionI
mpl@27813cf
The second iteration entering "java:comp/env" returned:
JNDI Names
JNDI Bindings
Quote
Hopefully you will find your data source under there somewhere.
Does this mean there is no data source configured under JNDI name space?
Here I have some further questions to ask. Hope you won't mind.
I am trying out connection pooling on WAS 4.0, using servlets not EJB. I
use the Admin Console to edit the data source JNDI naming, following the
sample data sources in WAS installation. Those are read: "jdbc/Something".
Therefore mine is "jdbc/TestDataSource". I explored one WAS site which
exemplifies binding to data sources. It cites that:
Quote
Bean-managed persistence bean
When developing your bean-managed persistence (BMP) bean you generally lack
knowledge about the name of the data source on the target application
server.>In your code, do not look up the data source directly. Instead, you
look up the resource reference from the java:comp/env namespace file. Let us
assume that>you look up the resource reference named ref/ds as illustrated
in the code below.
Quote
javax.sql.DataSource dSource = (javax.sql.DataSource)((new
InitialContext()).lookup("java:/comp/env/ref/ds"))
(javax.sql.DataSource)javax.rmi.PortableRemoteObject.narrow( (new
IntialContext()).lookup("jdbc/Section"), javax.sql.DataSource.class);
Quote
In the AAT, you specify the name ref/ds in the Resource Reference page on
the General Tab. If you know the name of the data source you can specify it
in this>Resource References page on the Bindings Tab. Note that if you do
not specify it here , you must provide this Java Naming and Directory
Interface (JNDI) name>when you install the application EAR file.
Quote
Container-managed persistence bean
In a container-managed persistence (CMP) bean you do not specify the
DataSource in the code. Instead you specify the JNDI name of the DataSource
during>assembly using the AAT, this is the setting in the Bean Binding
panel. In this example, the JNDI name jdbc/Section is used.
Quote
Servlets and JavaServer Pages Files
In a servlet application, you look up the DataSource exactly as you look it
up in the BMP bean case.
Given the last statement above, is it necessary to deploy my servlet using
the AAT? If yes, how is this achieved in JBuilder?
Thanks,
Patrick
 

Re:Re: WAS 4.0 JDBC/JNDI problem

"Lori M Olson [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote

Hopefully you will find your data source under there somewhere.

I got from some articles that the problem might happen if the data source
is not properly referenced. I examined the web.xml and found no
<resource-ref>there. I opened the Web App DD editor and created one,
redeployed, but still failed. I examined again the web.xml and found the
content had the following added :
<resource-ref id="ResourceRef_1093432118937">
<res-ref-name>ResourceRef1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
</resource-ref>
The JNDI name was not added. I did add the name in Resource Reference page
of the Web App DD editor.
I visited a WebLogic site and found that WebLogic uses two descriptor files
for JNDI mapping:
Servlet code:
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup
("myDataSource");
web.xml entries:
<resource-ref>
. . .
<res-ref-name>myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
. . .
</resource-ref>
weblogic.xml entries:
<resource-description>
<res-ref-name>myDataSource</res-ref-name>
<jndi-name>accountDataSource</jndi-name>
</security-role-ref>
Do you have idea how the approach is in WebSphere?
Thanks,
Patrick
 

Re:Re: WAS 4.0 JDBC/JNDI problem

Patrick Wong wrote:
Quote


Do you have idea how the approach is in WebSphere?

Thanks,

Patrick


I'm afraid not. You see, I'm a WebLogic user myself. I could have told
you all that about the WebLogic stuff, but I didn't think it would
translate to WebSphere very well.
Basically, you have a problem deploying a data source. One thing you
have not mentioned, though. Have you deployed a JDBC connection pool?
Because in order to deploy properly, the DataSource needs a connection
from a connection pool.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Re: WAS 4.0 JDBC/JNDI problem

Patrick Wong wrote:
Quote
[...] I did add the name in Resource Reference page
of the Web App DD editor.

I visited a WebLogic site and found that WebLogic uses two descriptor files
for JNDI mapping:

Servlet code:

javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup
("myDataSource");

web.xml entries:

<resource-ref>
. . .
I should have mentioned this before, but
you are basically posting to the wrong
newsgroup for this type of problem. This
is either an "enterprise" or "servlets-jsp"
newsgroup type of problem. I'd post to
enterprise first because that's where the
folks who deal with app servers hang out.
I doubt they hang out here, since "database"
implies DataSet and its kin, not datasources,
app server descriptor files and the like.
Having said that, ...
Quote
Do you have idea how the approach is in WebSphere?
Are there really *no* WebSphere examples which utilize
a datasource? There must be.
Quote
I am trying out connection pooling on WAS 4.0, using servlets not EJB. I
use the Admin Console to edit the data source JNDI naming, following the
sample data sources in WAS installation. Those are read: "jdbc/Something".
Therefore mine is "jdbc/TestDataSource". I explored one WAS site which
exemplifies binding to data sources. It [explains
the way to do it in an EJB, not in servlets ...]
In your exploration using Lori's JNDI exploring JSP
it does not appear that you tried *just* "jdbc". For your
servlet, the "java:comp/env" isn't appropriate; if
I remember correctly, the latter naming (ENC) is
the province of the EJB container, not the servlet
container.
Try plugging in "jdbc" into Lori's JSP, assuming
that you are still using "jdbc/TestDataSource"
as in your earlier posts.
You mentioned IBM docs; how about this one
which differentiates between adding the resource
reference to an EJB (Container or Application) and
to a Web application (Container or Servlet):
tinyurl.com/3lywv (that's an "el", not "one")
See section "Adding a JDBC resource reference to an (EJB or
Web) deployment descriptor".
Finally, if you are using JBuilder X, *assuming* that your
WebSphere Web app project has a Web Module node, double-click
on that node, go to the structure pane, double-click
on the node "Resource References". Is your data source
definition there? Is it named "jdbc/TestDataSource"?
--
Paul Furbacher (TeamB)
Save time, search the archives:
www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.