LDAP Query from Java taking abnormally long

Is there any reason why this query would take an abnormally long time? When I run the query from the command line it comes back practically instantly, but when I access it via Java it takes close to 30 seconds.
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
public class LDAPTest {
      * @param args
     public static void main(String[] args) {
          String username = System.getProperty("user.name");
          String LDAPServer = "ldap://ldap.myldapserver.net/";
          //String attribute = "";
          String query = "uid=" +username;
          Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, LDAPServer);
        DirContext context = null;
        NamingEnumeration enumeration = null;
          try {
               context = new InitialDirContext(env);
            SearchControls ctrl = new SearchControls();
            ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
            enumeration = context.search("", query, ctrl);
            //while (enumeration.hasMore()) {
                 SearchResult searchResult = (SearchResult) enumeration.next();
                Attributes attributes = searchResult.getAttributes();
                Attribute attr = attributes.get("cn");
                String cn = (String) attr.get();
                System.out.println(" Person Common Name = " + cn);
        } catch (NamingException e) {
            throw new RuntimeException(e);
        } finally {
            if (enumeration != null) {
                try {
                     enumeration.close();
                } catch (Exception e) {
            if (context != null) {
                try {
                     context.close();
                } catch (Exception e) {
}

njb7ty wrote:
One way to speed it up is to only retreive those attributes your interested in via ctls.setReturningAttributes.
Also, if you know what sub directories you want to look in, you can create a list of just those subdirectories and look through them one at a time via ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes((String[])attrIDs.toArray(new String[attrIDs.size()]));
//only look at the immediate folder level specified (not in sub-folders)
ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);Hi, thanks. I tried these, unfortunately I don't know enough about ldap to set the onelevel_scope properly. I have narrowed it down as a combination of load and login issues. For example, in our test environment the java program returns instantly with anonymous. In our production environment it returns in about 30-40 seconds with no login credentials supplied. (it does allow anonymous access). I made sure I set the authentication to none when attempting to try this. But when I do an anonymous query from the command line via a ldapsearch program it pulls the results instantly. (i know it is anonymous because if I specify credentials it pulls back additional data). For some reason it just takes really long to resolve in our production environment if I try anonymous access and I haven't figured it out yet. When I supply login credentials to our production environment it comes back in under a fifth of a second.

Similar Messages

  • BEx Query from Java

    Hi
    Can I call a BEx Query from Java . If yes, in what format data will be returned? We just need data, we want to structure it in Java for display in a Flex UI.
    Please note that I have very limited knowledge of both Java and BI.
    Thanks in advance for your help.
    Best Regards
    Saurabh

    Hi,
    Yes you can. It will be contained in a web template.
    Please read through the link below and the related links contained within.
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/0d/af12403dbedd5fe10000000a155106/frameset.htm
    Thanks,
    Michael
    Edited by: Michael Devine on May 25, 2010 3:40 PM

  • Construction of a new ServerSocket taking abnormally long - ipv6-related

    SUMMARY
    It takes 180+ seconds to open a ServerSocket if IPv6 is present on the loopback device.
    SYSTEM
    Debian unstable
    Linux desktop3.mgn 2.4.27-speakup #1 Fri Feb 25 15:43:38 EST 2005 i686 GNU/Linux
    java version "1.4.2_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
    Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
    MORE INFO
    Last place within PlainSocketImpl everything's alright is     /**
         * Load net library into runtime.
        static {
         java.security.AccessController.doPrivileged(
                new sun.security.action.LoadLibraryAction("net"));
         initProto();
        }After the call to initProto (which is a native method) it takes 180+ seconds for the last connect() call below (got i from running strace) to timeout:socket(PF_INET6, SOCK_STREAM, IPPROTO_IP) = 5
    listen(5, 1)                            = 0
    getsockname(5, {sa_family=AF_INET6, sin6_port=htons(37753), inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 0
    socket(PF_INET6, SOCK_STREAM, IPPROTO_IP) = 6
    connect(6, {sa_family=AF_INET6, sin6_port=htons(37753), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=3221214872}, 24) = -1 ETIMEDOUT (Connection timed out)TEST PROGRAMimport java.net.*;
    public class Test {
         public static void main(String[] args) {
              try {
                   long start = System.currentTimeMillis();
                   ServerSocket serverSocket = new ServerSocket(4445);  // <-- this is what takes abnormally long
                   long stop = System.currentTimeMillis();
                   System.out.println("stop - start = " + (stop - start));
              } catch (UnknownHostException e) {
                   e.printStackTrace();
                   System.exit(-1);
              } catch (java.io.IOException e) {
                   e.printStackTrace();
                   System.exit(-2);
    }CASE "ON"# ip a show dev lo
    1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
        inet6 ::1/128 scope host
    $ java Test
    stop - start = 189011CASE "OFF"# ip a del ::1/128 dev lo
    # ip a show dev lo
    1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
    $ java Test
    stop - start = 18Commands executed to "turn ipv6 on/off":ip a del ::1/128 dev lo
    ip a add ::1/128 dev loNo other programs show this delay. Is this a bug?

    I think so, I've read something like that in BugParade.
    Try Java5 or Java6 (Mustang) with your code.
    --Marc                                                                                                                                                                                                                           

  • Problem while querying from java

    I have a query like this ...
    Select name,description,start_date from Events where TO_CHAR(start_date,'MM/DD/YYYY')='09/19/2004';
    I want to execute the same query using java for which i say
    String QQQ="Select name,description,start_date from Events where TO_CHAR(start_date,'MM/DD/YYYY')='?/?/?'"
    PreparedStatement stmt = conn.prepareStatement(QQQ);
    stmt.setString(1,"09");
    stmt.setString(2,"27");
    stmt.setString(3,"2004");
    But I am not getting the results. Is there anything wrong with the Qusetion marks(?) in the query ?
    I get the results if i directly enter the value for the question mark.
    Please help.
    Thanks.

    Date date = get a Date object somehow, perhaps from SimpleDateFormat.parse()
    String query = "Select name,description,start_date from Events where start_date = ?";
    PreparedStatement ps = con.prepareStatement(query);
    ps.setDate(1, date);
    ps.executeQuery();

  • How to open a brio Query from Java

    Hi,
    I am working with Hyperion Intellegence Explorer to take care of the MIS related activities, to pull out the Data from the Data Base and Export it to the Excel
    Actually this is a BAU.
    So i want to reduce my work burdon. I am a Java Progrrammer too. So i want to automate all the thing from Java.
    Pls help me below to open a Brio files from Java,so that i can proceed to process the Query and export it on to the Excel.,

    Don't double post the same question. You can continue in your previous thread
    [http://forums.sun.com/thread.jspa?threadID=5367120]
    I'm locking this one and it will be removed it later.
    db

  • To Open a Brio Query from Java

    Hi,
    I am using Hyperian Intellegence Explorer to get a information from the Data Base.
    I want to do it automatic,because this we are doing this as a BAU.
    I want to reduce my work load ,so thatpln to write a Code.
    Please help me how to Open an existing BrioQuery from Java.

    corlettk wrote:
    http://geocities.com/khory_scythe/Praxeum/jedicode.html
    Yeah that fits... except I swear a lot. Is that allowed?
    Jedi use their powers to defend and protect, never to attack others.Can we throw an exception for this one?
    edit: actually i disagree with the whole jedi code, its wrong, wheres the fun...
    Mel

  • Database query from Java

    I'm writing a Java program that needs to query a Microsoft Access database. I'm not sure how to do this. Someone said to use ODBC drivers but I don't know what these are. Any clarification/ideas would be appreciated.

    There are a few easy step to set up a connection to your database in your java program.
    1. establish an odbc data source in windows control panel (may be under Administrative tools).
    2. you need to import the java.sql package.
    3. you need a connection, so type the following into your database class:
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    connection = DriverManager.getConnection("jdbc:odbc:/*your data source name goes here*/");
    catch (ClassNotFoundException exception)
    System.err.println("Failed to load JDBC/ODBC driver");
    exception.printStackTrace();
    System.exit(1);
    catch (SQLException exception)
    System.err.println("Unable to connect");
    exception.printStackTrace();
    System.exit(1);
    }4. Find an SQL tutorial on the web.
    5. For each query/update etc create a Statement object using the following code:
    try
    Statement statement = connection.createStatement();
    /* now use the remainder of this try block to execute your query. Each database query returns a ResultSet object */
    ResultSet resultSet = statement.executeQuery("/*your query string goes here*/");
    /* the next() method in ResultSet returns true if there are any more records, like an iterator. Therefore, you know if there are any results or not*/
    if (resultSet.next())
    /* If your query was a 'SELECT * FROM ...etc' then you will get a whole row from the table(s) within the database. if you need to extract a number from that record and you know the column number, then use the following */
    int id = resultSet.getInt(1);
    /* where 1 corresponds to the first column in the table, and so on. Ifyou want to extract a String, the use the getString() method*/
    catch (SQLException exception)
    }That's basically the easiest way to go about it (I think). Best to consult a book for a more in-depth look. Try Java - How to Program, by Deitel and Deitel (available at www.deitel.com). I found this very useful.

  • Using mdx query from Java Apache

    Please suggest/guide me how to use MDX query to pull data from cube from Apache JAVA??
    BI GUY

    Hi BIGUY,
    Multidimensional Expressions (MDX) is the query language that you use to work with and retrieve multidimensional data in Microsoft Analysis Services. MDX is based on the XML for Analysis (XMLA) specification, with specific extensions for SQL Server Analysis
    Services.
    According to your description, it's hard to give your the exact MDX query to pull the data which you want from the cube since there are no any detail information about the cube. Here are some basic knowledge for your reference.
    Querying Multidimensional Data with MDX
    MDX Sample
    Regards,
    Charlie Liao
    TechNet Community Support

  • Ms Access query from Java

    I'm trying to finish a program but there are some bugs in accessing the database, the connection opened well and i can retreive any data from the data base but when i wrote this sql statement:
    rs = stmt.executeQuery("Select number,Type, sum(charge) from invoice where date between '" + d1 +"' and '"+ d2 + "' Group By number, Type;");
    an error was appeared with:
    "data type mismatch in criteria expression"
    the d1 and d2 are variables with date datatype
    in invoice table "date" is an attribute with date/time datatype..
    anyone to help me??
    thanks all

    the real problem here that in java d1 and d2 areNo the real problem is your refusal to use Prepared Statements.
    converted from from string to date data type
    so it consists of: dayname, day , month, hour, and
    year
    and in MS Access the date attribute is consist of
    day, month and year only.. If you used Prepared Statements then this would not matter.
    so when i compare these d1and d2 in java with date in
    ms access it cause miss match data type error..
    how to make d1,d2 in the format "dd/mm/yyyy" and
    still date data type???
    USE PREPARED STATEMENTS.
    java.sql.PreparedStatement
    Look that up. Annie gave you an example in her post.

  • Running mysqldump query from java code

    Hello,
    I m making a program I want to take a backup of database on a click of a button for which i want to execute this query :
    "mysqldump --user=root --password=root --opt dbname>c:\backup.sql"
    and my code is :
    String command = "cmd /c start";
    String[] env = new String[]{"mysqldump","--user=root", "--password=root",
    "--opt", "njitsurvey", "<", "c:\\backup_db.sql" };
    File dir = new File("C:/Program Files/MySQL/MySQL Server 5.0/bin/");
    Process p1 = Runtime.getRuntime().exec(command, env, dir);
    My problem is my command is running and going in to the directory also but not running my query and i m not getting and error also
    Edited by: purva on Aug 7, 2008 11:56 PM

    You need to print the content of the process error stream ( p1.getErrorStream() ) . It would also be worth you while reading http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
    Also, you seem to think that setting the working directory toFile dir = new File("C:/Program Files/MySQL/MySQL Server 5.0/bin/");makes this the directory from which 'mysqldum' is found. It is not. The directory containing the executable has to on the PATH. The working directory is where the process looks for and creates data files if the full path to the files is not provided.
    Edited by: sabre150 on Aug 8, 2008 10:41 AM
    Also, you seem to think that the 'env' is the command executed! It is not. It the set of environment variables. You need to put the whole of the command as the first argument.
    Edited by: sabre150 on Aug 8, 2008 10:46 AM

  • Exporting or Copying from Desktop Taking a Long Time

    Hello-
    I am a super user.
    I ran a standard report set up by our administrator, then altered it by adding two new fields and adding a condition. The report ran in less than a minute and returned 6864 rows. For some reason, the report will not export and I cannot do a copy-paste from Desktop to Excel. Under either scenario, I get the hourglass for several minutes (over 30).
    Why would a report that queries and runs quickly slow down when I try to export it?
    Thanks

    4. what happens if you try to export as something else such as an HTML file?
    ***I didn't try this, but I need Excel, not HTML.
    The reason I asked if you'd tried exporting to a different filetype is that I was trying to ascertain if it's Discoverer as such, or the tool it's being exported to has changed, updated, driver,, etc.
    For example if it exports quickly with all rows to another format (html for example) then it might help as knowing it seems to be only an Excel problem.
    Additionally:
    I ran a standard report set up by our administrator, then altered it by adding two new fields and adding a condition. The report ran in less than a minute and returned
    6864 rows. For some reason, the report will not export and I cannot do a copy-paste from Desktop to Excel. Under either scenario, I get the hourglass for several
    minutes (over 30).Could you get the owner of the workbook to create another version for you with your minor changes and then see if that one runs quickly and can be exported. If not, I wonder if it's a privilege setup (for exporting) and a security setup (query doesn't come back) as they can do something you can't.
    Finally, what Disco flavor is it? (desktop, plus, viewer)?
    Russ
    Edited by: Russ Proudman on Nov 6, 2008 2:27 PM

  • HT1689 Why is my tv show i bought from itunes taking so long to download?

    I bought a season of a tv show on itunes yesterday on my ipad and there are 16 episodes. I let my ipad sit overnight and they still didnt download! Only 2 out of 16 downloaded!! Plz helpp!

    I am experiencing the same thing. All downloads from appldnld.apple.com.edgesuite.net are very slow. This includes iTunesSetup and Quicktime. I have been trying to download the new version of iTunes for a few days, but I get too impatient. 90 minutes for 57 meg isn't cool. I have no other issues with the internet only this site. FWIW my ISP is Verizon DSL in Southern California.

  • HT1766 Why is my restore taking so long?

    Why is my iPhone 5 restore from iCloud taking so long?

    I FOUND A SOLUTION as to why the iCloud restore to my iPhone 5 was taking so long (3 days).
    It basically boiled down to my phone trying to download & restore iTunes music from my other apple id. It asked for it initially, but the tech on the phone told me I could skip it...don't skip it. My music is with one id (macbook) and my apps are with my most used id (iphone).
    I checked my phone to see if I had iTunes music waiting to download/reinstall...and there was, but it wasn't downloading. 
    On my phone, I went to settings, icloud, signed out of my most used id, signed in to my other id, downloaded that music, then signed back out.
    My phone was ready to go in seconds!
    **I highly suggest using wifi to perform your iCloud restore***
    I was on my way to the Genius Bar in the morning, but now things are resolved. I really hope this helps someone!

  • SQL Queries from Java to Access

    Does anyone know why it is that when i send a SQL query from a Java class to Access using the equals ( = ) function, it works fine, but when i send a query using the LIKE function, it does not work?
    If i manually copy and paste the LIKE query from Java into an Access query, the query works fine yet when i send it from the Java class, it does not work.
    An ideas would be most welcome

    Access uses a different token for the %-sign (a * I believe). When you want to do a 'like-query' through JDBC, you have to use the %-sign:
    LIKE '%text_to_search%'

  • Db link Query in Java

    I 'm executing a sql query from Java. The sql has data from two different database and i'm using db link for the same.
    But my java program connects to only one database. So my program is throwing "connection description ofrm remote database not found" error.
    How can i change my java program which will solve this issue?

    GaneshJay wrote:
    I 'm executing a sql query from Java. The sql has data from two different database and i'm using db link for the same.
    But my java program connects to only one database. So my program is throwing "connection description ofrm remote database not found" error.
    How can i change my java program which will solve this issue?Doesn't sound like an application error, it's probably a database error. What happens if you execute the query in the database through a tool? (Query browser?)

Maybe you are looking for

  • Making sure attached images and signatures appear in the body of sent email

    The subject line says it all. I would like recipients of my mail to see the attachment/image or signature, within the body of the email where I have placed it.....or not if I so choose. Is this possible to control from the sender's end?....or is this

  • To get the IP Address: request.getRemoteAddr()

    Dear All, I need to verify the IP address of any request after an user logs in. Can I use request.getRemoteAddr()? If the user is accessing my web site using dynamic IP address, DHCP etc, will I get a different IP address after a while? Thanks. WITH

  • Console keeps opening

    I have a Macbook Air with Mavericks. When I startup from shutdown or sleep mode, the Console application opens up. Is there a way for this not to occur?

  • NOW LIVE: Oracle Database 11g - Performance Tuning Exam (1Z0-054)

    !http://blogs.oracle.com/certification/ORC-0128.jpg! The new *"Oracle Database 11g: Performance Tuning" certification exam (1Z0-054)* is now live, which is a single exam requirement for Oracle 11g DBA OCPs to earn the Oracle Database 11g Performance

  • AIP-50547:  Trading partner agreement not found for the given input values

    I am trying to setup outbound 810. I have it working in one environment I took export and imported in another environment. But it gave me following error. I purged repository and configured everything again and it still gives me same error: 2007.08.2