Performance - using JDBC call with 'order by' vs sorting data on app server

Hello! I need some valid thoughts on the performance of using a JDBC call versus processing information on the application server.
Here is the somewhat simplified scenario:
I need to retrieve customer information (name, e-mail, telephone), display it in HTML format and then be able to redisplay it in a different order. For example, initially the list would be displayed sorted by last name, but then a user might choose to sort it by e-mail address. Initial call to DB uses 'order by' in the SQL stmt to get me the initial ordering by last name. Results are stored in 2D array. However, when a user selects a different sort I have two options:
1) just make another call to the DB with a different order by clause. This means I need to create a DB connection, connect to DB, retrieve the results and read them from result set into a 2 dimensional array
2) re-sort data in the 2D array populated during the initial call. This means I need to use java.util.Arrays.sort(my_2D_resultsArray, my_custom_comparator)
Question is : which is more efficient? Number of entries retrieved can be anywhere from 0 to a few thousands (depending on other filters such as customer's country). My feeling is that option umber 2 is better, but I would like to get your opinion.
Thank you!

Good points! Thanks! I ran a test (see code below) and it takes less than a second to sort 2000 Strings and 2000 nulls. The only thing I ran the test at a UNIX prompt as oppose to from within app server (Weblogic). I expect the speed to be compatible though. Do you think that test was valid and tells us that sorting on the app server is probably faster than doing another SQL query?
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Arrays.*;
public class Test {
  public static void main(String[] args) throws Exception {
    Test test = new Test();
    test.testSortingPerformance();
  public void testSortingPerformance() {
    Object[] objArray2 = new Object[]{};
    Vector v = new Vector();
    Date start, end;
    java.util.Random rd = new java.util.Random(2000);
    for (int i = 0; i < 2000; i++){
      v.add(new Object[]{new String("" + rd.nextInt())});
      v.add(new Object[]{null});
    objArray2 = v.toArray();
    Object[] innerObjArray2 = new Object[]{};
    MyComparator2 myComp = new MyComparator2();
    start = new Date();
    java.util.Arrays.sort(objArray2, myComp);
    end = new Date();
    for (int i = 0; i < objArray2.length; i++) {
      System.out.println();
      innerObjArray2 = (Object[])objArray2;
for (int j = 0; j < innerObjArray2.length; j++) {
System.out.print(innerObjArray2[j] + " ");
System.out.println(v.size());
System.out.println("Start " + start + " End " + end);
import java.util.*;
public class MyComparator2
implements Comparator {
//position in the inner array to use for comparison
private int position = 0;
//default empty constructor
public MyComparator2() {
//implement compare method
public int compare(Object o1, Object o2) {
Object[] strAr1 = (Object[]) o1;
Object[] strAr2 = (Object[]) o2;
if (strAr1[0] == null){
if (strAr2[0] == null){
return 0;
else{
return -1;
else if (strAr2[0] == null){
return 1;
return ( (String) strAr1[0]).compareTo( (String) strAr2[0]);

Similar Messages

  • Problem with READ DATASET when reading file from app server

    Hi,
    wondering if anyone can help, I'm using the following code to read from a file on app server, the file is of type .rtf
    OPEN DATASET file_rtf FOR INPUT IN TEXT MODE
                                 ENCODING DEFAULT
                                 WITH SMART LINEFEED.
    DO.
    READ DATASET file_rtf INTO string.
    IF SY-SUBRC = 0.
    EXIT.
    ENDIF.
    ENDDO.
    the open dataset part works sy-subrc = 0, but the read returns sy-subrc = 8 and no data is passed to string.
    Any ideas as to what is causing this problem appreciated, <removed>
    Thanks
    Edited by: Thomas Zloch on Mar 17, 2010 3:57 PM - please don't offer p...

    Hi Adam,
    The source code in the below link has details about how to read/write to application server.
    [Application server file operartions|http://www.divulgesap.com/blog.php?p=NDk=]
    Please let us know if you have any issues.
    Regards,
    Ravi

  • How to use a parameter with Order By?

    I am trying to pass in a parameter to a procedure (like 'ColumnName ASC, ColumnName DESC') to use with ORDER BY, but I can't get it to order on the passed in parameter? I have read a few posts but non of my attempts have worked.
    Procedure getEquipmentList(io_cursor OUT ref_cursor_Equipment), orderString IN VARCHAR2, RecordStart IN NUMBER, RecordEnd IN NUMBER) IS
    Equipment_Cursor refCursor_Equipment;
    Use_Order NUMBER := 1;
    BEGIN
    OPEN Equipment_Cursor
    FOR SELECT *
    FROM TABLE(
    PACKAGE_EQUIPMENT.getRecordSetOfEquipment(
    CURSOR(
    SELECT * FROM (SELECT idEquipment, strEquipmentName, deletedFlag, Row_Number() OVER (ORDER BY DECODE(Use_Order, 1, orderString)) AS r FROM tblEquipment) WHERE r >= RecordStart AND r <= RecordEnd)));
    io_cursor := Equipment_Cursor;
    END;
    If I replace orderString in the DECODE with say strEquipmentName it orders correctly. If I try 'strEquipmentName' then it does not work. Any ideas would be helpful.

    SQL>
    SQL> create or replace procedure test2(ord in varchar2)
    2 is
    3 TYPE TCUR IS REF CURSOR;
    4 CUR TCUR;
    5 v_name varchar2(30);
    6 begin
    7 open cur for 'select first_name from employees where rownum<=10 order by '||ord;
    8 loop
    9 fetch cur into v_name;
    10 exit when cur%notfound;
    11 dbms_output.put_line(v_name);
    12 end loop;
    13 end;
    14 /
    Procedure created
    SQL> exec test2('employee_id');
    Steven
    Neena
    Lex
    Alexander
    Bruce
    David
    Valli
    Diana
    Nancy
    Daniel
    PL/SQL procedure successfully completed
    SQL> exec test2('salary');
    Diana
    Valli
    David
    Bruce
    Daniel
    Alexander
    Nancy
    Lex
    Neena
    Steven
    PL/SQL procedure successfully completed
    SQL>

  • How to get numeric information about system performance using WMI calls?

    Hello everyone,
    I'll make the question summarized for your convenience. I want to achieve the following task:
    -To be able to measure system performance over a sustained period of time.
    The way I intend to tackle that task is by doing the following:
    -To use WMI calls to get system performance data in a numeric and/or a percentage form. (RAM utilization, CPU utilization, Power state [active/idle]). 
    The information I am trying to get is EXACTLY the information you can see in Task Manager under Performance tab. 
    Please help. If you think there is a better way to do this than using WMI calls, I couldn't be more glad to take your advice and apply it!!
    Thanks in advance!
    Ray

    There is a better way.
    Use PDH function calls. This gets you as close as you can get to the performance counters provided by the operating system.
    Read more about it here.
    Examples found here.
    Codeproject example here and
    here

  • I want to Know how to use JDBC connection with postgress sql on Linux

    Hello friends R u Listen to me?
    Pls help me for making JDBC connectivity with postgress Sql On Linux by using Type 4 Driver .
    Is there is any envoirnment setting rqr then pls send me the same on my mail
    My mail is [email protected]
    varsha

    dcminter wrote:
    http://java.sun.com/docs/books/tutorial/jdbc/index.html
    and
    http://www.postgresql.org/docs/
    ;-)

  • Using control reference with a Sub-vi over a TCP VI Server connection

    I tried to use a Call by Reference Node to run a sub-vi on a remote PC through a TCP VI Server. An output of the sub-vi is connected to an indicator in the main vi using a control reference.
    The sub-vi started on the remote PC, but the information from the sub-vi was not passed to the control reference in the main vi. However, if I change the client name to the host PC, ie. running the server and client vi on the same machine, the code works as planned. I wonder if control reference is not suppose to work over a TCP VI Server connection?
    Any suggestion would be very much appreciated.
    Regards,
    Calvin Tsang
    Attachments:
    main_vi.vi ‏29 KB
    sub_vi.vi ‏20 KB

    Thank Jean-Pierre for pointing out that Refnums are local to an application and so control reference doesn't work between different applications on separate machines.
    In addition to the method shown in Jean-Pierre's example vi, I found that the use of "invoke method: GET control value" and "invoke method: SET control value" can produce similar results. See the attached files for an example. In this example, the indicator on the local vi is used to monitor the progress of the remote vi and the local control is used to stop the remote vi. So the data synchronisation between the two vi is not important here.
    However, you may notice the indicator "current counter" in main1_vi.vi doesn't properly interpret the binary string from "invoke method: GET control
    value", can someone shed some light on this, please?
    Calv
    Attachments:
    main1_vi.vi ‏48 KB
    sub1_vi.vi ‏13 KB

  • Implementing Oracle DCN with Coherence Cache in a weblogic 10 app server

    I m trying to implements a DCN ( Database change notification ) on oracle to notify a listener of an event of DB so I can update Coherence Cache.
    I followed the tutorial here and it is working fine using a sample program with a main method to execute the listener class and keep it running.
    My question is how would this notification and listener gets implemented on a production environment since my local test was only running a main method to keep the listener running? what technology to use to keep the listener always running on the background and receive the notification from the database )?
    would a [weblogic startup class|http://docs.oracle.com/cd/E13222_01/wls/docs81/ConsoleHelp/startup_shutdown.html] work for this purpose?
    We are using Weblogic 10 as our app server.

    That's a very simple question with (many) potentially complex answers. I think that first uou need to study information on TimesTen to understand what it is and what it does. Then you need to relate that to you current performance bottleneck (I assume you have analysed those). If your bottleneck is database access then maybe TimesTen can help you.
    Please bear in mind that TimesTen is not a 'transparent' drop in performance booster. To implement TimesTen and to realise significant performance improvement you will almost certainly need to make changes to both the application and the overall architecture. The cost/difficulty of doing that also needs to be factored in.
    Chris

  • Calling Reports 10g from Forms 10g without an app server

    Hi
    I have Forms 10g, and for development/testing purposes I am able to run a form in my local machine using the standalone OC4J. I needn't to deploy the form to test it.
    I can do the same with Reports 10g -- run a report in my local machine without an app server.
    However, I could not manage to call a Report from a Form that way, without an app server. It does not seem possible -- is it? Is there a way to set this up using the standalone OC4J or something like that?
    Thanks
    Luis
    Message was edited by:
    Luis Cabral

    Hi
    Sorry for the late reply.
    Here's how you start the report server from windows XP machine.
    1. Choose a unique name for the report server. Eg. <your_pc_name>_repserver
    2. As the report server runs in its own process, it can be started by the following command, accessible from the \ bin directory of the
    Oracle Developer Suite or Oracle Application Server 10g installation.
    rwserver –install <server_name> . It is now treated as a windows service and hence you can stop/start or restart from the services menu.
    3. If you want specific settings for your report server, look for the <rep_server_name>.conf file under <orahome>/reports/conf directory, after starting the server from above command. This file is created by oracle automatically, once the rep server gets started.
    For more info on this, please refer to white papers on the Forms and reports integration, found on the otn->Forms.
    Hope this helps
    Suma

  • "Unable to load IAmWebPolicy" with Policy Agent 2.2 on Sun App Server 8.2

    I'm trying to install the Policy Agent for App Server 9.0/9.1 to App Server 8.2 (which claims to be supported). Identity Manager is the target resource. I get this when I try accessing the /idm root context:
    Exception caught in AmWebPolicyManager initializer: Unable to load IAmWebPolicy: com.sun.identity.agents.policy.AmWebPolicy
         at com.sun.identity.agents.policy.AmWebPolicyManager.<clinit>(AmWebPolicyManager.java:135)
    Thanks,
    Steve Maring

    You were absolutely correct
    I've resolved this issue - the problem was caused by two things:
    1. There is a new version of a library called libxml2.so that I had to get from Sun (they provided version 2.6.7)
    2. My web server with the agent on it is on a seperate box from the identity server. These two servers were out of sync in terms of their system time (ie, the solaris box with the agent / web server was about 8 minutes ahead of the solaris box with the identity server)
    Once both of these things were fixed (the time issue most importantly), the web server would not hang anymore.

  • Problem using JDBC driver with JSP

    Hi, I am trying to connecto to my mysql server via a JSP page, but it seems that there is a problem with the driver call or something in my configuration that unables me to connect. I have the mysql-connector-java-3.0.7-stable driver.
    This is how my classpath looks like:
    CLASSPATH=/home/hooper/Sources/mysql-connector-java-4.0.7-stable/lib:/home/hooper/Sources/mysql-connector-java-3.0.7-stable/com:/home/hooper/Sources/mysql-connector-java-3.0.7-stable/mysql-connector-java-3.0.7-stable-bin.jar:/usr/java/j2sdk1.4.1_02:.:/usr/java/j2sdk1.4.1_02/lib/tools.jar:/usr/java/j2sdk1.4.1_02
    And this is my JSP page code:
    <%@ page language="java" import= "java.sql.*"%>
    <%
    Connection con = null;
         String userName = "hooper";
         String password = ""; //No password
         String url = "jdbc:mysql://localhost/test";
         //Load the Driver class file
         Class.forName("com.mysql.jdbc.Driver");
         //Make a connection to the MySQL database
         con = DriverManager.getConnection (url, userName, password);
         out.println ("Database connection established");
              if (con != null){
                   //Close the connection
                   con.close();
    %>
    And this is the error I get from Tomcat4.1.18:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: com.mysql.jdbc.Driver
    root cause
    javax.servlet.ServletException: com.mysql.jdbc.Driver
    I hope someone can help me with this.
    Thanks,
    Luis

    Hi..
    Try using this way
    String userName = "hooper";
    String password = ""; //No password
    String url = "jdbc:mysql://localhost:3306/test";
    Class.forName("org.gjt.mm.mysql.Driver");
    try to download the driver for mysql and add it to your classpath
    Hope this works
    Regd
    Vasi

  • Slow JDBC calls with wrong configured DNS

    We recently found out that a wrong configured DNS Server can cause oracle JDBC Clients to react extremly slow. (1 second per simple sql statment)
    We have found also that if the DNS server is disabled on server side (8.1.7.1 Oracle, Redhat 6.2 server) the system responds with normal speed.
    It seems for us that Reverse lookups are done for any SQL Statement sent from the client and not only for the first connection.
    Does anybody know how to disable this Reverse DNS-Lookups on Server side because this may also cause a slowdown if the DNS-Server is correctly configured or all clients are defined in /etc/hosts.
    Thank you in advance!

    We recently found out that a wrong configured DNS Server can cause oracle JDBC Clients to react extremly slow. (1 second per simple sql statment)
    We have found also that if the DNS server is disabled on server side (8.1.7.1 Oracle, Redhat 6.2 server) the system responds with normal speed.
    It seems for us that Reverse lookups are done for any SQL Statement sent from the client and not only for the first connection.
    Does anybody know how to disable this Reverse DNS-Lookups on Server side because this may also cause a slowdown if the DNS-Server is correctly configured or all clients are defined in /etc/hosts.
    Thank you in advance!

  • How to improve performance using bulk collects with plsql tables or arrays

    Hi All,
    my procedure is like this
    declare
    cursor c1 is select ----------------------
    begin
    assigning to variables
    validations on that variables
    --50 validations are here --
    insert into a table
    end;
    we have created indexes on primary keys,
    i want to use
    DECLARE
    CURSOR a_cur IS
    SELECT program_id
    FROM airplanes;
    TYPE myarray IS TABLE OF a_cur%ROWTYPE;
    cur_array myarray;
    BEGIN
    OPEN a_cur;
    LOOP
    FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
    ***---------can i assign cursor data to the plsql table variables or array***
    ***validate on the pl sql variable as---***
    i
    nsert into a table
    EXIT WHEN a_cur%NOTFOUND;
    END LOOP;
    CLOSE a_cur;
    END;
    Edited by: Veekay on Oct 21, 2011 4:28 AM

    Fastest way often is this:
    insert /*+append */
    into aTable
    select * from airplanes;
    commit;The select and insert part can even be done in parallel if needed.
    However if the oparation is complex or the dataset is very very very very very large or the programmer is decent but not excellent then the bulk approach should be considered. It is often a pretty stable and linear scaling approach.
    The solution depends a little on the database version.
    LOOP
      FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
      EXIT WHEN a_cur.count = 0;
      forall i in a_cur.first.. a_cur.last
      insert into aTable (id)
      values (a_cur(i));
    END LOOP;
    ...If you have more then one column then you might need a single collection for each column. Other possibilities depend on the db version.
    Also: do not exit using a_cur%NOTFOUND. This is wrong! You might loose records from the end of the data set.

  • Buffer size for SQL statement using JDBC calls

    I need to find out the buffer size for SQL statements in jave/JDBC because I need to insert or update a field that could be up to 4KB in size.

    I'm not sure that I follow the question; I'm not sure which buffer size you're referring to.
    If you have a field that can store up to 4k worth of data, you would create a VARCHAR2(4000) column in the Oracle database (assuming it is character data) or a BLOB column (if the data is binary). Either of those two fields can be populated from JDBC.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Problem to calculate the coherence (using NetworkFunction-VI) with only 1 row of data for each, the stimulus and response input

    Hello,
    I am trying to calculate the coherence of a stimulus and response
    signal using the Network Functions (avg) VI's. The problem is that I
    always get a coherence of "1" at all frequencies. This problem is
    already known (see KnowledgeBase document: Why is the Network Functions (avg) VI's Coherence Function Output "1"?).
    My trouble is that the described solution (-> the stimulus and response input matrices need to have at least two rows to get non-unity coherence values) doesn't help me much, because I only have one array of stimulus data and one array of response values.
    Thus, how can I fullfil the 'coherence-criteria' to input at least two rows of data each when I just have one row of data each?
    Any hint or idea is very much appreciated. Thanks!
    Horst

    With this weird board layout, I'm not sure whether you were asking me, but, on the assumption that you were, here goes:
    I found no need to use the cross-power spectrum and power spectrum blocks
    1... I was looking for speed.
    2... I already had the component spectral data there, for other purposes. From that, it's nothing but addition and multiplication.
    3... The "easy" VIs, assume a time wave input, as I recall. Which means they would take the same spectrum of the same timewave several times, where I only do it once.
    I have attached PNGs of my code.
    The PROCESS CHANNEL vi accepts the time wave and:
    1... Removes DC value.
    2... Integrates (optional, used for certain sensors).
    3... Windows (Hanning, etc. - optional)
    4... Finds spectrum.
    5... Removes spectral mirrors.
    6... Scales into Eng. units.
    7... From there, you COULD use COMPLEX-TO-POLAR, but I don't care about the phase data, and I need the MAG^2 data anyway, so I rolled my own COMPLEX-TO-MAG code.
    The above is done on each channel. The PROCESS DATA vi calls the above with data for each channel. The 1st channel in the list is required to be the reference (stimulus) channel.
    After looping over each channel, we have the Sxx, Syy, and Sxy terms. This code contains some averaging and peak-picking stuff that's not relevant.
    From there, it's straightforward to ger XFER = Sxy/Sxx and COHERENCE = |Sxy|^2 / (Sxx * Syy)
    Note that it uses the MAGNITUDE SQUARED of Sxy. Again, if you use the "easy" stuff, it will do a square-root operation that you just have to reverse - it is obtained faster by the sum of the squares of the real and imag parts.
    Hope this helps.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    ProcessChannel.png ‏25 KB

  • How to use oracle APEX with an distant database located on a distant server

    Hi there,
    I'm a brand new user with Oracle Technologies. I've installed ORACLE 10g XE and updated APEX to 4.0 version on my laptop.
    My Manager has setup a distant server with a Linux Red Hat. He has installed on this server EBS R12 with a 11i database.
    As a training, I'd like to play with the tables located on the server with the APEX 4.0 installed on my laptop.
    As the server is on the same local network and following the description above, is it possible to plug my local APEX to the server database ?
    If not, does it mean I have to install APEX on the 11i server database and then connect to the server to play with those tables ?
    Thanks a lot for your time and support ACEs members.
    Regards,
    Ulrich

    Hi Ulrich,
    yes, you can access other database from your APEX database. The mechanism used to do this is called a "database link". You need to create such a database link in your local database, then you can access the remote database like this:
    SELECT *
      FROM databaselink@EMP
    ;If you want to use such remote objects from within APEX you need to create local views to wrap this (search the forum for apex and database links, you'll find interesting threads).
    brgds,
    Peter
    Blog: http://www.oracle-and-apex.com
    ApexLib: http://apexlib.oracleapex.info
    BuilderPlugin: http://builderplugin.oracleapex.info
    Work: http://www.click-click.at

Maybe you are looking for

  • Need to create sales out of purchase order using idocs

    Hi All, I have a requirement to create sales order based on purchase order with in the same sap system and same client(using orders04 idoc type).I have some doubts below could you please some body clarify? I know the basic steps in ALE(theritical kno

  • How can I automatically re-size an imported PDF when I re-size the window?

    I and using RoboHelp HTML 8 and Acrobat Pro 9.  Once I "reduce file size," I can import PDFs with no problem and they look fine when I view them.  But if I re-size the browser window, the images of the PDFs stay the same size, getting more or less bl

  • Safari keeps unexpectedly closing!

    PLEASE HELP! safari keeps unexpectedly closing on me, I don't know what to do. This is report I keep sending to apple: Process: Safari [461] Path: /Safari.app/Contents/MacOS/Safari Identifier: com.apple.Safari Version: 3.2.1 (5525.27.1) Build Info: W

  • Working with LDB without selection screen

    can' we take input through file without any selection screen when we are working with LDB? Please focus on this. Regards vamsi.

  • How to convert an anchor point to have a single control point...

    Can anyone tell me if it is possible to convert an existing anchor point on a path from a dual control point with directional handles either side of the point to a single control point with one directional handle? In Illustrator this is easy, all you