Results 1 to 1 of 1
  1. #1
    RBNSN is offline Member
    Join Date
    Jul 2010
    Rep Power

    Default ERROR WHILE TRYING TO CONNECT MySQL( javax.naming.NameNotFoundException)

    Hello and Good day to every one,
    I am trying to build a DB based application that will validate login ID of users.
    The application will

    Ask the user to input his "username" and "password"
    Check the existence of this user in the Data Base
    If exists, Retrieve his first name and last name from the DB and display them
    If not registered, Display "Sorry, you are not registered".

    The folder structure of the project can be referred from the Attachement. The Main class that handles connection to the database is the ConnectionManager. java . The code is as below.
    Java Code:
    package ExamplePackage;
    import java.sql.*;
    import java.util.*;
    import javax.naming.*;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    public class ConnectionManager {
    	static Connection con;
        static String url;
        public static Connection getConnection(){
        	String DATASOURCE_CONTEXT = "java:comp/env/jdbc/important_schema";
        	Connection result = null;
        	try {
    			//Initialize the Context
    			Context initialContext = new InitialContext();//Create a pointer to the root of the JNDI tree.
    			//Create a DataSource object
    			DataSource ds = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);
    			//Get a connection from a pool of pool of JDBC connections with the getConnection() method of a DataSource object.
    			Connection con = ds.getConnection();
    		} catch (RuntimeException e1) {
    			// TODO Auto-generated catch block
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    		} catch(SQLException ex){
    		return con;

    The settings for the datasource in my WeblOGic Server is shown in the attached picture.

    When I try to run the project and key in the Username and password, I get an error as below.

    Your user name is ROBINSON
    Your password is FRANCIS
    Query: SELECT * FROM users where username='ROBINSON' AND password='FRANCIS'
    javax.naming.NameNotFoundException: While trying to look up comp/env/jdbc/important_schema in /app/webapp/LoginExample/4240780.; remaining name 'comp/env/jdbc/important_schema'
    at weblogic.jndi.internal.BasicNamingNode.newNameNotF oundException(
    at weblogic.jndi.internal.ApplicationNamingNode.looku p(
    at weblogic.jndi.internal.WLEventContextImpl.lookup(W
    at weblogic.jndi.internal.WLContextImpl.lookup(WLCont
    at r.lookup(
    at weblogic.jndi.internal.AbstractURLContext.lookup(A
    at javax.naming.InitialContext.lookup(InitialContext. java:392)
    at ExamplePackage.ConnectionManager.getConnection(Con
    at ExamplePackage.UserDAO.login(
    at ExamplePackage.LoginServlet.doGet(LoginServlet.jav a:34)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:820)
    at weblogic.servlet.internal.StubSecurityHelper$Servl
    at weblogic.servlet.internal.StubSecurityHelper.invok eServlet(
    at weblogic.servlet.internal.ServletStubImpl.execute(
    at weblogic.servlet.internal.ServletStubImpl.execute(
    at weblogic.servlet.internal.WebAppServletContext$Ser :3498)
    at t.doAs(
    at known Source)
    at weblogic.servlet.internal.WebAppServletContext.sec uredExecute(
    at weblogic.servlet.internal.WebAppServletContext.exe cute(
    at java:201)
    at :173)
    Log In failed: An Exception has occurred! java.lang.NullPointerException

    Can you please help me on this? I was told that it has got to do with the way the jdbc datasource is named in the Weblogic console but I am not sure. Please help me on this. Thank you all in advance.
    Attached Thumbnails Attached Thumbnails ERROR WHILE TRYING TO CONNECT MySQL( javax.naming.NameNotFoundException)-mysql-datasource-configuration..bmp  

Similar Threads

  1. javax.naming.NamingException:
    By arunpatil in forum Networking
    Replies: 1
    Last Post: 08-21-2010, 07:03 PM
  2. Replies: 2
    Last Post: 08-07-2009, 11:21 PM
  3. Replies: 4
    Last Post: 07-06-2009, 06:25 AM
  4. javax.naming.NameNotFoundException: bean not bound
    By Sirisha_24 in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 04-01-2009, 11:51 AM
  5. javax.naming.NameNotFoundException: ejb/RatingEJB
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 06-29-2007, 03:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts