How to use JNDI lookup from a JSP

Hello,
I know I should not be doing this (writing the lookup code in a JSP) but have to do it for some reasons.
I am using this code in my JSP:
try
     Context ctx = new InitialContext();
     dataSource = (DataSource)ctx.lookup("jdbc/mybillingora");
     conn = dataSource.getConnection();
     statement = conn.createStatement();
catch(Exception excep)
Is this code enough for a JNDI look up?? When I use this code, I get an exception:
"javax.naming.NameNotFound exception:jdbc/mybillingora"
Do I need to do something else??
Why do we use :
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"<some_context_factory>");
env.put(Context.PROVIDER_URL, PROVIDER_URL);
env.put(Context.SECURITY_PRINCIPAL, JNDI_USER);
env.put(Context.SECURITY_CREDENTIALS, JNDI_PWD);
InitialContext = new InitialDirContext(env);
where JNDI_USER is the userid If ACL is configured at the JNDI server
where JNDI_PWD is the password If ACL is configured at the JNDI server
Context.INITIAL_CONTEXT_FACTORY is the initial Context factory and depends on ur JNDI service provider.
PROVIDER_URL is the url of the JNDI server containing protocol/ip/port
do i need to use this??
would appreciate your help on this....
Thanks

If Tomcat is your servlet/JSP engine, they have a nice bit about how to do it:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
MOD

Similar Messages

  • UserTransaction -  Scope using JNDI lookup from jspInit() method

    Howdy,
    I'm using JSP's with JavaBeans accessing a DataSource and some other enviroment variables using JNDI lookups. I've read that JNDI lookups can take a fair amount of time and should be limited whenever possible. My previous configuration had the JNDI lookups inside the constructors of the JavaBeans but I've recently decided to move them to the jspInit() method of the calling JSP. This way the lookup only needs to be performed once and then I pass the values to the JavaBean in a method called setContextVariables. Two of the references to objects that i'm sending are the UserTransaction and DataSource objects. Within the Javabeans I have userTran.begin() and commit() statements. So far it's running great but i'm starting to wonder about the thread safety of this method. My question lies in the actual delagation of the UserTransaction object to the calling client method. It seems that i'm passing the same transaction to every Javabean (or am I?) Is the transaction actually issued when the begin() method is called, or at the time of the JNDI lookup? To test everything out, I opened two sessions and put a breakpoint inside one of the transactions. When I stopped at the breakpoint I ran another thread (also using a transaction retrieved from the same JSP). Then I went back and resumed the first thread and everything seemed to work ok. So... this seems completely fantabulastic so far (definitely noticable response time increases) but I'm still a little skeptical. If anyone is using a process similar to this I would appreciate some feedback. Thanks.

    Hi,
    The EJB bean will use the client transaction when the following attributes are specified in descriptor.
    1) Required
    2) Mandatory
    3) Supports
    In Required case, if the client is associated with Transaction, then the EJB bean will use the same transaction. This is achieved by Transaction context. The EJB bean will use the same transaction context set by client. if the client doesn't have any transaction, then the container will create new transaction context for EJB bean and completes the transaction.
    In Mandatory case, the client must be associated with Transaction so that EJB bean will use the same transaction. If the client doesn't associate with transaction, then container will throw TransactionRequiredException for EJB bean.
    In Supports case, it works similar to Required case except that if the client doesn't associate with transaction, then there won't be any transaction in EJB bean.
    hope this helps.

  • How to use JNDI lookup

    Hi ,
    I am creating a POC for my project.Its using ATG and spring frameworks using RAD 6.first I have created ATG sample project in that same EAR file i created sample Spring project.Both are running in the same EAR.
    I want to use spring classes from ATG components to use those methods.that is i should pass parameters to spring project methods and i should get the return value after executing those methods.
    I heard that using JNDI look up I can get spring project class objects using that I can invoke spring project methods.
    My requirement is two projects will be running in the same EAR.But one project will not be having information about other projects.both are independent from other.Using JNDI look up i need to invoke Spring project methods.
    Please anyone help me how to do this.
    I used java:comp/env/com/dao/EmpDAO to get instance of my class EmpDAO.But i am getting naming exception.Can anyone help me how to do this
    Thanks in advance.

    If Tomcat is your servlet/JSP engine, they have a nice bit about how to do it:
    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
    MOD

  • JNDI lookup from a JSP page (URGENT)

    Hello,
    In my JSP I was using the "conn = DriverManager.getConnection("URL","username", "password")" scheme
    to connect to the database. I want to change this to use the JNDI for the database lookup in the same JSP.
    After creating this JSP i am using the include directive to include this JSP in all my other JSPs so that I can get the connection on other JSPs too.
    My included JSP where I use the JNDI look up is:
    <%@ page import="javax.naming.*,javax.sql.DataSource,java.sql.*" %>
    <%!
    static Connection conn;
    static Statement statement;
    static DataSource dataSource;
    %>
    try{
         Context ctx = new InitialContext();
         dataSource = (DataSource)ctx.lookup("MY_JNDI_NAME");
         conn = dataSource.getConnection();
         statement = conn.createStatement();
    }catch (Exception excep){
         out.println("Exception occurred "+excep);
    %>
    After I include this JSP in my main JSP, i get some error:
    188: Type expected. } catch (Throwable t) { ^ 1 error
    Can anyone here please help how to fix this.
    Thanks

    <%@ page import="javax.naming.*,javax.sql.DataSource,java.sql.*" %>
    <%!
    static Connection conn;
    static Statement statement;
    static DataSource dataSource;
    %><% // <-- you were missing a "<%" here
    try{
    Context ctx = new InitialContext();
    dataSource = (DataSource)ctx.lookup("MY_JNDI_NAME");
    conn = dataSource.getConnection();
    statement = conn.createStatement();
    }catch (Exception excep){
    out.println("Exception occurred "+excep);
    %>If I run that code in tomcat I get "Exception occurred javax.naming.NameNotFoundException: Name MY_JNDI_NAME is not bound in this Context". Which is what I would expect.
    btw: You really shouldn't be doing this stuff in a jsp.

  • How to use JDBC Lookup in PI 7.1 ?

    Hi,
    Please advise how to use JDBC lookup in message mapping PI 7.1 ? any reference link / document  ?
    I have followed this step below :
    1. Create the external definition for the database table.
    2. Use the external definition (table) in message mapping JDBC Lookup.
    But the target still "Yellow colour" meanint the mapping hasnot completed yet ? why ? and when i double click the JDBC lookup
    there some error message
    "No suitable parameter found; define new parameter of type 'Channel' first"
    Please advise.
    Thank You and Best Regards
    Fernand

    Hi Fernand,
    JDBC Lookup can be done in PI 7.1 using below mentioned steps :
    1) Create a communication channel between PI and the database to connect to database.
    2) Import the table data as External Definition.
    3) In message mapping where this lookup is to be used select JDBC Lookup under Conversions and map
    4) Double Click on JDBC Lookup
    5) Select parameter and a database table (imported as the external definition). All the elements of the table will appear in the middle column. Select and move the input parameters to the left side column and the output parameters to the right side column. Click OK. 
    6) Under message mapping go to signature tab and define the parameter as channel and category as JDBC Adapter Type. 
    7) Under Operation mapping define the parameter & associate it with parameter defined in Message Mapping.
    Thanks
    Amit

  • Anyone knows how to do JNDI lookup with OracleAQ?

    Hi all;
    Can anybody point me some guide/idea on how to implement JNDI lookup with OracleAQ?
    (Creating connectionFacotry , parameters for "java.naming.factory.initial", java.naming.provider.url etc..)
    Thanks
    -Ratha
    Edited by: Ratha on Sep 27, 2011 3:50 AM

    import javax.naming.*;
    import javax.naming.directory.*;
    import java.util.Properties;
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, PROVIDER_URL);
    env.put(Context.SECURITY_PRINCIPAL, JNDI_USER);
    env.put(Context.SECURITY_CREDENTIALS, JNDI_PWD);
    InitialContext = new InitialDirContext(env);
    where JNDI_USER is the userid If ACL is configured at the JNDI server
    where JNDI_PWD is the password If ACL is configured at the JNDI server
    Context.INITIAL_CONTEXT_FACTORY is the initial Context factory and depends on ur JNDI service provider.
    PROVIDER_URL is the url of the JNDI server containing protocol/ip/port
    Hope it helps
    -aseem

  • How to use debug my jdevloper devloped jsp applications using tomcat 4.0?

    hello,
    how to use debug my jdevloper devloped jsp applications using tomcat 4.0?
    how to run with using tomcat path with browser?
    can any one help?
    thanks
    pullareddy

    Hi Pullareddy,
    Charles' answer will work for Servlets in Tomcat, but debugging JSPs is a bit more complicated than debugging Servlets.
    Here's what you need to do:
    (I don't have Tomcat, so I don't know the details of Tomcat configuration files and I can't guarentee that Tomcat provides the flexibility so that you can configure it for debugging JSPs. Each application server is configured a bit differently. Hopefully you can adjust the following instructions to Tomcat.)
    1. You need to replace Tomcat's JSP engine with OJSP and you need to setup debugging parameters for OJSP.
    This is not specifically in the JDev documentation, but you may be able to apply the information found in the topic "Remote Debugging in OC4J".
    Here are some tips:
    A. You'll probably need to specify the following jars in some Tomcat config file: ojsp.jar, ojsputil.jar, xmlparserv2.jar, ojc.jar, and jdev-rt.jar.
    B. The OJSP class name is oracle.jsp.runtimev2.JspServlet.
    C. The debug parameters are:
    debug_mode = true
    developer_mode = true
    encode_to_java = true
    emit_debuginfo = true
    jspjavacompiler = oracle.jdevimpl.jsp.JspOjcCompiler
    2. You need to make Tomcat start the Java command with debugging options. (This is what Charles was talking about. One of the debug options is -XXdebug). This is in the JDev documentation in the topic "Starting a Java Process in Debug Mode". Please read that documentation help topic.
    3. You need to delete any old .java or .class files which were created in the past for your JSP. If you leave old .java or .class files around, then the debugger may not be able to stop at breakpoints in your JSPs. So, be sure to clean up old files.
    4. Set your project settings for remote debugging. This is on the Debugger - Remote panel in the Project Settings dialog box. You probably want either Attach to OJVM or Attach to JPDA. Which radio button you choose depends on what command line options you specified in step 2.
    -Liz

  • HT1491 how to use a ringtone from a downloaded app in iphone5

    how to use a ringtone from a downloaded app in iphone 5

    RINGTONE
    This how to make ring tones for your iPhone:
    Choose the desired song from you library
    Do a secondary click on your song if you are using a MAC (right click for PC)
    Click "Get Info"
    Go to Options tab
    Set Start Time and Stop Time, some iOS only allow for a 30 sec duration for ringtones, then click OK
    Do secondary click (right click for PC) to your selected song
    Click "Create AAC Version", new song from your selected will added to your library (short one)
    Do secondary click (right click for PC) to your short one (new song)
    Click "Show in Finder"
    Rename file *.m4a to *.m4r, click "use *.m4r"
    Drag the file to library, for the first time it would automatically add your library with new folder "Tones" under Apps folder
    Open the ring tones in the Tones folder of your library than drag it to your iPhone and your ringtone also would be automatically added "Tones" folder.
    Last but not least, set the ring tone in your iPhone under the "Setting-Sound"
    For information on how to make ringtones read http://www.ehow.com/how_2160460_custom-iphone-ringtones-free.html
    Or
    http://www.demogeek.com/2009/07/31/how-to-add-custom-ringtones-to-your-iphone/

  • How to use budget amount from previous years

    Dear Values Consultant
    How to use budget amount from previous years
    I create budget for 2007 and I use it .in 2008 I create new budget with new amount for account, but still there are amount from 2007-I want to use or transfer it to 2008,
    How to do this? Please give me details step to implement to this feature
    Thanks for caring

    Hi,
    There are two ways to do it:
    1. Define the account range in your Budget Organization and in the Budgetary Control region, out the Amount Type as "PJTD" and Boundary as "Project". This method is useful when you have project as a segment in your chart of accounts and the Budgets are defined for the full project.
    2. The Other way is to carry forward your funds available from last year. Go to Journals -> Generate -> Carry Forward and carry forward the balance for a certain range of account from one financial year to the next one.
    Gajendra

  • How to use iphone 4s from japan locked by softbank ?

    how to use iphone 4s from japan locked by softbank?

    Ocean20 answered your question, don't waste your time contacting Softbank as Chris CA suggested. There are no officially unlocked iPhones sold in Japan & none of the Japanese carriers...which include Softbank...offer official unlocking for the iPhone. There is no way to get any Japanese iPhone officially unlocked.

  • How to use JNDI look up from a JSP

    Hello,
    I know I should not be doing this (writing the lookup code in a JSP) but have to do it for some reasons.
    I am using this code in my JSP:
    try
         Context ctx = new InitialContext();
         dataSource = (DataSource)ctx.lookup("jdbc/mybillingora");
         conn = dataSource.getConnection();
         statement = conn.createStatement();
    catch(Exception excep)
    Is this code enough for a JNDI look up?? When I use this code, I get an exception:
    "javax.naming.NameNotFound exception:jdbc/mybillingora"
    Do I need to do something else??
    Why do we use :
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "<some_context_factory>");
    env.put(Context.PROVIDER_URL, PROVIDER_URL);
    env.put(Context.SECURITY_PRINCIPAL, JNDI_USER);
    env.put(Context.SECURITY_CREDENTIALS, JNDI_PWD);
    InitialContext = new InitialDirContext(env);
    where JNDI_USER is the userid If ACL is configured at the JNDI server
    where JNDI_PWD is the password If ACL is configured at the JNDI server
    Context.INITIAL_CONTEXT_FACTORY is the initial Context factory and depends on ur JNDI service provider.
    PROVIDER_URL is the url of the JNDI server containing protocol/ip/port
    do i need to use this??
    would appreciate your help on this....
    Thanks

    I am working on a pretty similar problem and posted my problem minute ago.
    Include JNDI.jar from <Oracle_HOME>\jlib. (This is what I found in Oracle docs).
    I presume you are also trying to create the Datasource using Datasource interface via JNDI rather than using Driver Manager.
    Thanks
    Mei

  • Calling BRM from UDF using JNDI lookup with @EJB annotation

    Hi Experts
    I am trying to implement a UDF to invoke my BRM Rules set via JNDI Lookup instead of a SOAP Channel lookup.
    I have had a look at the following links/docs:
    Calling BRM from UDF using Public API
    http://www.gleanster.com/system/resources/W1siZiIsIjIwMTIvMDgvMDcvMjAvNDcvNTAvNDMvVGhpbmdzX1lvdV9TaG91bGRfS25vd19hYm91dF9TQVBfTmV0V2VhdmVyX0JSTS5wZGYiXV0/Things%20You%20Should%20Know%20about%20SAP%20NetWeaver%20BRM.pdf
    For item 1 above, the example looks really good, but it doesnt explain how I get access to the following required imports from my UDF:
    import com.sap.brms.qrules.ejb.*;
    import com.sap.brms.qrules.engine.AbstractProject;
    import com.sap.brms.qrules.engine.RuleEngine;
    import com.sap.brms.qrules.engine.RulesetContext;
    import javax.ejb.EJB;
    The second document is really good as well, but I could not figure out how to get it to work from my UDF.
    So, can anyone help me to understand specifically what is required to get this to work?
    Is is possible to invoke the rule set from my UDF?
    How do I give my UDF access to all the required jars/imports?
    I have manage to create a new DC (Development Component) with a public part and this enables me to get my code to compile on my local PC but I am not able to activate it due to the server not having access to the same java packages as my local copy.
    Any help would be greatly appreciated.

    You resolve the dependency by importing the required jars with using the dependency tab for the mapping program.
    As stipulated before, I have managed to resolve the dependency issue but I have now getting the same error as in the forum: Calling BRM from UDF using Public API
    The specific error is:
    com.sap.engine.services.cross.PortableRemoteObjectContainer.narrow(PortableRemoteObjectContainer.java:238)
    Has anyome manage to get invoke a BRM Ruleset using JNDI?

  • Calling non ejb from ejb using jndi lookup

    Is it possible to call a non ejb java object from an ejb using a jndi lookup?
    For example, we have a java class where main registers itself with our application server (JBoss 3.0.1). We have a test client that can use jndi to look up the object, but we can't get an ejb inside the application server to use the object.
    Are we trying to do the impossible? If my question is not clear, please let me know so I can try to clarify.
    Thanks

    JNDI uses factories to create objects.
    It's possible that JBoss has a Bean Factory which you can use to create your instance.
    Tomcat has a Bean factory in its JNDI implementation. I use it just as you have indicated.
    The JBoss documenation may help?
    Dave

  • How to use JNDI to lookup remote EJB Home?

    Hello,
    I am writing a servlet to call a remote EJB on another machine.
    I use JNDI to lookup remote EJBHome (not) but fail.
    Any advice?
    Any trick to configure application-client.xml?
    Thanks!

    Use com.evermind.server.rmi.RMIInitialContextFactory instead
    Here an example
    // EmployeeClient.java
    package mypackage5;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.io.*;
    import java.util.*;
    import java.rmi.RemoteException;
    import com.evermind.server.ApplicationClientInitialContextFactory;
    import com.evermind.server.rmi.RMIInitialContextFactory;
    * A simple client for accessing an EJB.
    public class EmployeeClient
    public static void main(String[] args)
    System.out.println("EmployeeClient.main(): client started...");
    try
    * initialize JNDI context by setting factory, url and credential
    * in a hashtable
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    //env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.ApplicationClientInitialContextFactory");
    env.put(Context.PROVIDER_URL, "ormi://koushikm:23791/application4");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "admin");
    * or set these properties in jndi.properties
    * or use container defaults if that's where client got launched from
    Context context = new InitialContext(env);
    * Lookup the EmployeeHome object. The reference is retrieved from the
    * application-local context (java:comp/env). The variable is
    * specified in the assembly descriptor (META-INF/application-client.xml).
    Object homeObject =
    context.lookup("HelloEJB");
    System.out.println("EmployeeClient.main(): bean found...");
    // Narrow the reference to EmployeeHome.
    HelloEJBHome home =
         (HelloEJBHome) PortableRemoteObject.narrow(homeObject,
    HelloEJBHome.class);
    System.out.println("EmployeeClient.main(): home narrowed...");
    // Create remote object and narrow the reference to Employee.
    HelloEJB remote =
         (HelloEJB) PortableRemoteObject.narrow(home.create(), HelloEJB.class);
    System.out.println("EmployeeClient.main(): remote created...");
    String message=remote.helloWorld("SUCCESS");
    System.out.println(message);
    } catch(NumberFormatException e) {
    System.err.println("NumberFormatException: " + e.getMessage());
    } catch(RemoteException e) {
    System.err.println("RemoteException: " + e.getMessage());
    } catch(IOException e) {
    System.err.println("IOException: " + e.getMessage());
    } catch(NamingException e) {
    System.err.println("NamingException: " + e.getMessage());
    } catch(CreateException e) {
    System.err.println("CreateException: " + e.getMessage());
    Hello,
    I am writing a servlet to call a remote EJB on another machine.
    I use JNDI to lookup remote EJBHome (not) but fail.
    Any advice?
    Any trick to configure application-client.xml?
    Thanks!

  • How to use .class files from jsp

    hi i want to use .class files in my jsp program can any one help me

    so if you are using pacakges here is normal example...
    say you .java code is something like...
    package com.util;
    public Class BeanUtility{
    }place the .class file at WEB-INF/classes/com/util folder if those folders are missing create it and place the .class file there. or pacakage it as a jar file & put it into WEB-INF/lib folder
    Now in jsp you can either use jsp:Usebean tag or use normal scriplets to create an instance of the nessary class...
    here is an example for you
    <%@ page language="java" import="com.util.BeanUtility" %>
    <%
    BeanUtility bn = new BeanUtility();
    %>however,i'd suggest you to make use of JSTL / Inbuilt tag libraries /MVC 2.0 approach for better maintainance & readablity.
    Hope this might help
    REGARDS,
    RaHuL

Maybe you are looking for