Results 1 to 1 of 1
- 10-26-2011, 06:18 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
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 e1.printStackTrace(); } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch(SQLException ex){ ex.printStackTrace(); } 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(BasicNamingNode.java:1139)
at weblogic.jndi.internal.ApplicationNamingNode.looku p(ApplicationNamingNode.java:144)
at weblogic.jndi.internal.WLEventContextImpl.lookup(W LEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLCont extImpl.java:380)
at weblogic.jndi.factories.java.ReadOnlyContextWrappe r.lookup(ReadOnlyContextWrapper.java:45)
at weblogic.jndi.internal.AbstractURLContext.lookup(A bstractURLContext.java:130)
at javax.naming.InitialContext.lookup(InitialContext. java:392)
at ExamplePackage.ConnectionManager.getConnection(Con nectionManager.java:25)
at ExamplePackage.UserDAO.login(UserDAO.java:30)
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 etServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invok eServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute( ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute( ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$Ser vletInvocationAction.run(WebAppServletContext.java :3498)
at weblogic.security.acl.internal.AuthenticatedSubjec t.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Un known Source)
at weblogic.servlet.internal.WebAppServletContext.sec uredExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.exe cute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(S ervletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread. java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java :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.
Similar Threads
-
javax.naming.NamingException:
By arunpatil in forum NetworkingReplies: 1Last Post: 08-21-2010, 06:03 PM -
Exception in thread "main" javax.naming.NameNotFoundException: jmx not bound
By Vartika in forum Advanced JavaReplies: 2Last Post: 08-07-2009, 10:21 PM -
[newbie] javax.naming.NameNotFoundException: toaster
By jon80 in forum New To JavaReplies: 4Last Post: 07-06-2009, 05:25 AM -
javax.naming.NameNotFoundException: bean not bound
By Sirisha_24 in forum Enterprise JavaBeans (EJB)Replies: 2Last Post: 04-01-2009, 10:51 AM -
javax.naming.NameNotFoundException: ejb/RatingEJB
By Daniel in forum Enterprise JavaBeans (EJB)Replies: 2Last Post: 06-29-2007, 02:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks