aspose file tools*
The moose likes JDBC and the fly likes Exception at JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception at JNDI" Watch "Exception at JNDI" New topic
Author

Exception at JNDI

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 14, 2004
Posts: 10336

Do you have a resource-ref entry in your web.xml?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 14, 2004
Posts: 10336

com.mysql.jdbc.Driver is not in your classpath. Make sure your driver files are in your classpath.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

The driver would be a part of the mysql-connector-x.x.x.jar file!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Paul and muthu
Kevin Smither
Ranch Hand

Joined: Oct 22, 2007
Posts: 30
you are not implementing JNDI...you're using it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception at JNDI