• 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

NameNotFoundException

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic