• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception at JNDI

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i try to implement jndi lookup using mysql
i get below error.please can any one tell me the reason
--------------------------------------
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
-------------------------------------
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have a context called jdbc in your namespace. This could be becasue the DataSource was misconfigured an could bnot be created. How are you configuring your DataSource? Can you show us your code?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

this is in my server.xml
---------------------------------------------
<Context path="/test" docBase="test" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/dbcp" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="vc23" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://vc033/test?autoReconnect=true" />
</Context>
----------------------------------------------

this is my method in my javaclass
------------------------------------
public void openConn() throws ClassNotFoundException, SQLException {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/dbcp");
if (ds != null)
dbaseConn = ds.getConnection();
}catch(Exception e){
System.out.println(">>>>>>>>>>>>>.Error:"+e.getMessage());
e.printStackTrace();
System.out.println("Exception openConn MYSQLDBHANDLER: "+e.toString());}
}
-------------------------------
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a resource-ref entry in your web.xml?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi paul,

sorry.. now i got it... i gave wrong database url

but now i have one doubt ... i am using mysql5.0

i try to access DataBase ...writing code in java file(simple jdbc steps)..

---------------------------------------
Class.forName("com.mysql.jdbc.Driver");
System.out.println("--------");
Connection conn=DriverManager.getConnection
("jdbc:mysql://vc033/test?autoReconnect=true","root","vc23");
---------------------------------------------------

i am getting Exception like below... please tell me the reason ?
-----------------------------------------
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
------------
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
com.mysql.jdbc.Driver is not in your classpath. Make sure your driver files are in your classpath.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The driver would be a part of the mysql-connector-x.x.x.jar file!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul and muthu
 
Kevin Smither
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are not implementing JNDI...you're using it.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic