Exception in creating InitialContext.
- From: "Manoj Jain" <Manoj.S.J@xxxxxxxxx>
- Date: 23 May 2006 01:00:13 -0700
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"));
}
}
.
- Follow-Ups:
- Re: Exception in creating InitialContext.
- From: Frank Langelage
- Re: Exception in creating InitialContext.
- Prev by Date: Re: State design pattern proliferation issue
- Next by Date: JMS and EJB
- Previous by thread: servlet redirect
- Next by thread: Re: Exception in creating InitialContext.
- Index(es):
Relevant Pages
|