Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Exception in creating InitialContext.

Thread view: 
Manoj Jain - 23 May 2006 09:00 GMT
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"));
   }
}
Frank Langelage - 23 May 2006 20:05 GMT
>                 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.