Exception in creating InitialContext.

M

Manoj Jain

hi
here is a class to make connectivity with Derby database. jndi name is
created for jdbc connectivity as jdbc/proformaInvoice
import com.maruti.proforma.dto.ConcreteLoginDTO;
import com.maruti.proforma.dto.LoginDTO;
import java.sql.*;
import java.util.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public final class Database {
private static DataSource ds=null;
private static Connection conn=null;
private static InitialContext ic=null;
private static Map <String,String> authMap=null;
private static Statement stmt=null;
private static ResultSet res=null;
/** Creates a new instance of Database */
private Database() {
}
public static void connect()
{
try
{
ic= new InitialContext(); //<----------here it gives
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

what is this exception for? what will I have to do then?
//rest is kept as to verify complete program
DataSource
ds=(DataSource)ic.lookup("jdbc/proformaInvoice");
conn=ds.getConnection();
}
catch(SQLException se){se.printStackTrace();}
catch(NamingException ne){ne.printStackTrace();}
}
public static boolean validate(LoginDTO loginDTO)
{
boolean bnFlag;
authMap=new HashMap<String,String>();
try
{
if(conn == null){System.out.println("Conn is null");}
stmt=conn.createStatement();
res=stmt.executeQuery("Select User, Password from
UserMaster");
while(res.next())
{

authMap.put(res.getString("user").toUpperCase(),res.getString("password"));
System.out.println(res.getString(1) + "
"+res.getString(2));
}
if(authMap.containsKey(loginDTO.getName()) &&
authMap.get(loginDTO.getName()).equals(loginDTO.getPassword()))
{
bnFlag=true;
}
else
{
bnFlag=true;
}
}
catch(SQLException se){bnFlag=false;}
return bnFlag;
}
public static void main(String[] args)
{
Database.connect();
Database.validate(new ConcreteLoginDTO("LEO","leo"));
}
}
 
F

Frank Langelage

Manoj said:
ic= new InitialContext(); //<----------here it gives
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

what is this exception for? what will I have to do then?


Do what the Exception's message recommends.
Use google to search for examples.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top