This is some old material I'm studying published by IBM (2001). They are using JnDi when I tried to apply their code:
try {hashtable env = new hashtable (); Env.put (reference. INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); // Create the initial reference context CTX = new initial concave (env); // Here we create actual datasource and then set the relevant // parameters. TdsDataSource DS = New TdsDataSource (); Ds.setServerName (Servername); Ds.setPortNumber (portnumber); Ds.setDatabaseName (DatabaseName); Ds.setUser (login); Ds.setPassword (password); Ds.setDescription ("JDBC Datasource Connection"); // Now we can tie a datasource object with the name already selected. Ctx.bind (file path, ds); Ctx.close (); // general exception handler, in practice, it will be replaced by a suitable / proper exception handling hierarchy} hold (exception before) {System.err.println ("Error:" + former. Messages); } But I found out that there is no "com.sun.jndi.fscontext.RefFSContextFactory" file system service provider. Then I changed the code (from) as follows.
OracleDataSource ods = New OracleDataSource (); Ods.setDriverType ("OCI"); Ods.setServerName ("dlsun999"); Ods.setNetworkProtocol ("TCP"); Ods.setDatabaseName ("816"); Ods.setPortNumber (1521); Ods.setUser ("Scott"); Ods.setPassword ("Tiger"); Reference CTX = New Initial Concert (); Ctx.bind ("jdbc / sampledb", ods); When I try to execute this code, I get the following error:
Error: Specify the class name in the environment or the system property Need to do this, or as an applet parameter or in an application resource file: java.naming.factory.initial I think it's still asking for reference . INITIAL_CONTEXT_FACTORY Any solutions? I am searching from dawn this morning. InitialContext
/ code> object should fix this problem.
System.setProperty (Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty (Context.URL_PKG_PREFIXES, "org.apache.naming"); It basically tells the system , which are the initial reference libraries you are using to store your data source references.
No comments:
Post a Comment