Meaningless Drivel is fun!*
The moose likes BEA/Weblogic and the fly likes NameNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "NameNotFoundException " Watch "NameNotFoundException " New topic
Author

NameNotFoundException

Bob Smilley
Greenhorn

Joined: Jan 16, 2002
Posts: 1
Dear All,
I am running weblogic 6.1, using Oracle 8i, and trying to follow an example from a book called, J2EE Applications and BEA WebLogic Server, Chapter 5, Using Databases and Transactions with JDBC and JTA, example myJDBCReadServlet.war.

I have the following settings.
Name: myConnectionPool
URL: jdbc racle:thin:@127.0.0.1:1521:Java1
Driver Classname: weblogic.jdbc.oci.Driver
Properties
(key=value): user=system
server=Java1

ACLName:
Password: change...
and for my DataSource:-
Name: myDataSource
JNDI Name: myconnection
Pool Name: myConnectionPool
Row Prefetch Enabled
Row Prefetch Size:
Stream Chunk Size: bytes
and when I try to run the following:-
http://127.0.0.1:7001/myJDBCReadServlet
I get the following error message.
<10-Jan-02 01:14:05 GMT> <Notice> <WebLogicServer> <Started WebLogic Admin Server "myserver" for domain "mydomain" running in Production Mode>
<10-Jan-02 01:14:15 GMT> <Info> <NT Performance Pack> <Allocating: '2' NT reader threads>
<10-Jan-02 01:14:21 GMT> <Info> <HTTP> <[WebAppServletContext(1713526,console,/console)] actions: init>
<10-Jan-02 01:14:28 GMT> <Info> <HTTP> <[WebAppServletContext(1713526,console,/console)] FileServlet: init>
<10-Jan-02 01:14:28 GMT> <Info> <HTTP> <[WebAppServletContext(1713526,console,/console)] FileServlet: Using standard I/O>
<10-Jan-02 01:15:09 GMT> <Info> <HTTP> <[WebAppServletContext(2230667,myJDBCReadServlet,/myJDBCReadServlet)] myJDBCReadServlet: init>
Init Error: javax.naming.NameNotFoundException: Unable to resolve myDataSource. Resolved: '' Unresolved:'myDataSource' ; remaining name ''
Service Error: java.lang.NullPointerException
<10-Jan-02 01:18:48 GMT> <Info> <Management> <Configuration changes for domain saved to the repository.>
Java source code:-
package com.learnweblogic.examples.ch5;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class myJDBCReadServlet extends HttpServlet {

/*
* This method is called when the servlet is first initialized.
* Note here that both the initial lookup into the WebLogic JNDI
* naming context and the location of a DataSource object from it
* are placed here. This ensures that the operations are only done
* once instead of every time that the servlet is accessed. This is
* very important for efficiency.
*/
public void init() {
try {
/* Create a connection to the WebLogic JNDI Naming Service:
*/
ctx = new InitialContext();
/* Create a new DataSource by Locating It in the Naming Service:
*/
ds = (javax.sql.DataSource)ctx.lookup("myDataSource");
} catch (Exception E) {
/*
Handle exception here.
*/
System.out.println("Init Error: " + E);
}
}

public void service(HttpServletRequest requ,
HttpServletResponse resp)
throws IOException
{
Connection myConn = null;
try {
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head><title>myJDBCReadServlet</title></head>");
out.println("<body>");
out.println("<h1>myJDBCReadServlet</h1>");
/* Get a new JDBC connection from the DataSource:
*/
myConn = ds.getConnection();
/* Create an Instance of the java.sql.Statement class
and use the factory method called createStatement()
available in the Connection class to create a new statement.
*/
stmt = myConn.createStatement();
/* Use the shortcut method the available in the Statement
class to execute our query. We are selecting all rows
from the EMPLOYEE table.
*/
rs = stmt.executeQuery("SELECT * FROM EMPLOYEE ");
/* This enumerates all of the rows in the ResultSet and
prints out the values at the columns named ID, NAME,
LOCATION.
*/
while (rs.next()) {
out.println(rs.getString("ID") + "- " +
rs.getString("NAME") + "- " +
rs.getString("SEX") + "<p>");
}
/* Release the ResultSet and Statement.
*/
rs.close();
stmt.close();
} catch (Exception E) {
/*
Handle exception here.
*/
System.out.println("Service Error: " + E);
} finally {
if (rs != null) {
try { rs.close(); } catch (Exception ignore) {};
}
if (stmt != null) {
try { stmt.close(); } catch (Exception ignore) {};
}
if (myConn != null) {
try { myConn.close(); } catch (Exception ignore) {};
}
}
}
/*
* Local Variables
*/
Context ctx;
DataSource ds;
Statement stmt;
ResultSet rs;
}

I would be most greatful for anyones help, in helping resovlethis JNDI problems.
Thanks
Bob S.
Ghulam Rashid
Ranch Hand

Joined: Jan 14, 2002
Posts: 278
Hi Bob,
From your error it seems that your DataSource name is not bounded with the JNDI Namespace.
Possible cause is in the target of DataSource you forget to assign ther server.
Or in the Deployment Descriptor while defining jndi-name for DataSource is not matching with the one you created from console.
Good Luck
Rashid
Pearlo Muthukumaran
Ranch Hand

Joined: Sep 17, 2002
Posts: 79
I encountered a similar problem in Message Driven Bean deployed on Weblogic 7.0.The error discovered was :
I had configured the JMS Server but i had not mentioned the target server under user domain i had created.
Solution:
I just deleted the server i had configured and added the server anew, this time i carefully chose the target server and then created the destination.
Result : Now the MDB worked perfect as expected.
Hope the 4 hours which i spent figuring out and rectifying the same would help others to save the same time
Good Luck
Muthukumaran
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
The problem here was he was trying to lookup the datasource by its WebLogic name, not by its JNDI name.
His Config:

His Code:

Code should have been:

The datasource name is just there so that WebLogic can identify it in a sensible way for the Administrator. As a developer we only care about the JNDI name.
Obviously this is a moot point since the original post is nearly a year old.
[ September 20, 2002: Message edited by: Chris Mathews ]
Jay Bhushi
Greenhorn

Joined: Jan 09, 2011
Posts: 1
Hi pearlo,

I am also facing the JNDI name not found exception issue. I am new to weblogic.
I have configured JMS queues. but still Im getting this exception. Probably i made some mistakes in targetting.
I think you know the exact solution.

My code/application is running fine in the production server. But problem exists while running in local system.
So I think this is not a code issue this is a local weblogic JMS configuration issue.


Thanks in advance..... Thanks a lot... Waiting for your reply.....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NameNotFoundException
 
Similar Threads
urgent help (on oracle connection pool)
Class name is wrong or classpath is not set
lass name is wrong or classpath is not set
unable to recognize jndi name when using myeclipse3.8.3
urgent help (on oracle connection pool)