hi,
i am working in jndi datasource for establishing database connection.
but i am not able to connect database, bcoz i got the below error. how can i clear the error?
i am using tomcat 5.5 server with eclipse editor.
here is my coding:
``````````````````
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class testJDBC {
public static void main(String[] args) {
Connection con=null;
DataSource ds=null;
Context initContext=null, envContext=null;
try
{
initContext = new InitialContext();
}catch(Exception e)
{
System.out.println("InitContext Exception");
e.printStackTrace();
}
try
{
envContext = (Context)initContext.lookup("java:comp/env");
}catch(Exception e)
{
System.out.println("envContext Exception");
e.printStackTrace();
}
try
{
ds = (DataSource)envContext.lookup("jdbc/mySQLServer");
}catch(Exception e)
{
System.out.println("DataSource Cast envContext Exception");
e.printStackTrace();
}
try
{
con=ds.getConnection();
}catch(Exception e)
{
System.out.println("get conntection from datasource Exception");
e.printStackTrace();
}
try
{
if (con!=null)
{
System.out.println("Connection Successfull");
}else
{
System.out.println("Connection Not Successfull");
}
}catch(Exception e)
{
System.out.println("conntection checking Exception");
e.printStackTrace();
}
}
}
here is the error details :
````````````````````````````
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at testJDBC.main(testJDBC.java:28)
java.lang.NullPointerException
at testJDBC.main(testJDBC.java:36)
java.lang.NullPointerException
at testJDBC.main(testJDBC.java:44)
plz help me
thanks and regards,
k.s.kumar