Query slow when executing using prepared statement compared to sqlDeveloper

Oracle version is 10.2.0.1.0.
I have got a query which when submitted from java code using prepared statement and parameter substitutions, takes more than 20 seconds to give results.
I can see this SELECT sql sitting there when I run Monitor Sessions through sqlDeveloper, with its wait time increasing and then finally getting through. During that time no other SQLs are waiting.
DURING THAT TIME then I am able to run the same query (with values included) multiple times using sqlDeveloper, and it gives results in no time.
Sqldeveloper connects using thin client using lib provided by oracle in windows.
Java code runs from linux and uses the thin client using lib provided by oracle in linux.
Both are hitting the same DB running on a separate Linux machine.
What could be the cause of this problem?
What db parameters, queries should I run to identify the bottleneck?
Edited by: user10390517 on Jun 14, 2010 3:06 AM

Hi Rob,
at least you should see some differences in the statistics for the different child cursor (the one for the execution in the application should show at least a higher value for ELAPSED_TIME). I would use something like the following query to check the information for the child cursors:
select sql_id
     , PLAN_HASH_VALUE
     , CHILD_NUMBER
     , EXECUTIONS
     , ELAPSED_TIME
     , USER_IO_WAIT_TIME
     , CONCURRENCY_WAIT_TIME
     , DISK_READS
     , BUFFER_GETS
     , ROWS_PROCESSED
  from v$sql
where sql_id = your_sql_idRegards
Martin

Similar Messages

  • When to use prepared statement in java?

    Hi all,
    If we have query like select * from {tablename} (Here tablename is the variable) then will the use of prepared staement improve the performance? My guess is use of statement in this case is a better option rather than prepared statement as the tablename may change for every other query.I think are not useful if tablename changes.They are useful only when the where clause has dynamic values.

    cantor wrote:
    Are you sure that your approach is possible? The next example causes exception for me.
    PreparedStatement ps = conn.prepareStatement("select * from ?");
    ps.setString(1, "TABLE_NAME");
    ps.executeQuery();
    I didn't say that he should solve it in that way. He should create one prepared statement like this "select a, b, c from tablename1" and another prepared statement when he wants to execute "select d, e, f from tablename2"
    >
    And as I understand, this code will not improve perfomance (and even will not work). As I said it can.
    Prepared statements make possible usage compiled queries inside DB. When DB gets prepared statement call, it need to parse it only once. And it can collect some statistic to improve execution plan. But when table name is not specified, this approach will not work.Yes it might. There are database drivers that can cache prepared statements and it's isn't likely that he executes that query on more than e.g. 20 tables?
    The database can also cache compiled statements in a cache.
    Kaj

  • Can getGeneratedKeys() be used when executing batches of statements?

    Hi all,
    this question was posted in this thread:
    Can getGeneratedKeys() be used when executing batches of statements?
    but unfortunately I didn't find the answered appropriate.
    That thread is now locked, so I would like to start it again here.
    This is a summary of the other thread:
    Can you retrieve keys generated by a batch of insert statements? The following code produces an ArrayIndexOutOfBoundsException from the Oracle T4CNumberAccessor.unmarshalOneRow() method (see stack trace at the bottom of this message).
    The code is:
    String sql = "INSERT INTO FOO (ID, NAME) VALUES (FOO_SEQ.NEXTVAL, ?)";
    String generatedColumns[] = {"ID"};
    PreparedStatement pstmt = connection.prepareStatement(sql, generatedColumns);
    pstmt.setString(1, "A");
    pstmt.addBatch();
    pstmt.setString(1, "B");
    pstmt.addBatch();
    pstmt.setString(1, "C");
    pstmt.addBatch();
    //EXCEPTION OCCURS HERE
    pstmt.executeBatch();
    The exception is:
    java.lang.ArrayIndexOutOfBoundsException: 22
    at oracle.jdbc.driver.T4CNumberAccessor.unmarshalOneRow(T4CNumberAccessor.java:190)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:610)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
    at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10580)
    The only answer given was:
    "You should directly specify how big your batching is. For that reason you may use ExecutionContext where you can set setBatchingLimit(int) and setBatching(bool). This operation will tell execution context the size of supposed batching and also should be batching performed at all or not. You can add batching jobs but you can not execute the jobs without proper initialization of batching job size - it will fail with out of bounds."
    ExecutionContext is not something I found in jdbc drivers, so I'm a bit confused about this answer.
    Did anyone solve the problem?
    Thanks,
    Michele

    >
    We have the same problem. No solution so far.
    >
    I never found a definitive solution but testing seems to show that this is not possible.
    There is no code that can be written to get the generated keys if batching is used.
    This is because the 'getGeneratedKeys' method must be called on the prepared statement and would return the generated keys as a ResultSet object. But when batching there is only one prepared statement but multple sets of parameters, one for each batch entry.
    Thus there could only be one call to 'getGeneratedKeys' since there is only one prepared statement. This strongly implies that it is not possible to use 'getGeneratedKeys' when batching.
    See Retrieval of Auto-Generated Keys in the JDBC Dev guide
    http://docs.oracle.com/cd/B19306_01/java.102/b14355/jdbcvers.htm#CHDEGDHJ

  • Advantages of using prepared statement..... ?

    can anyone please tell me that what r the advantages of using prepared statements.
    for eg in case if statement object is executed inside a for loop where query is executed multiple times the sql query is compiled outside loop and therefore compilation is done only once. which makes sense
    But if there the query is not executed multiple times then what is the real benifit of using prepared statement . because the statement object will be closed after executing the query.
    and a new statement object will be created when other user access the same code.
    please clearify my doubts
    thanks
    Pankaj

    Other advantages of using PreparedStatement:
    1. It's easier to create SQL that looks like "Select This, That, TheOther from Something where ID=? and Usage=?" than to try to generate that with string concatenations.
    2. You don't have to deal with escaping quote characters that happen to appear in strings you want to insert in your database.
    3. PreparedStatements can do some things that Statement can't, such as updating very large text columns.

  • Resultset from a batch select using prepared statement

    Hi,
    Is it possible to add results of batch execute of select statements and retrieve the result set ..
    I am running select statement in a batch mode setting in value for a column.I add this to a prepared batch.
    I would like to get the reults as a batch and spin through the result set like a r.next(). Is this possible ?
    I have given the code below
    sql = "select ordervalue , orderdate from discreet_orders "+
    "where order_no = ? ";
    dbObject.prepareStatement(sql);
    dbObject.prepareStatement(sql);
    for (int i=0; i < orderNoVect.size(); i++) {
    dbObject.setString(1,(String)scnV.elementAt(i));
    dbObject.addBatchPrepared();
    r = dbObject.execPrepared();
    dbObject.clearBatchPrepared();
    I would like to do a r.getNext() process the values form the resultset.
    Is this possible ? If not is there an other way to do it ?
    Thanks
    Arnold

    Olek wrote:
    hi
    Is there a way do a batch update using prepared statement?
    I don't want to insert every row in a single query...
    regards,
    OlekPossibly the confusion here stems from the existence of two addBatch methods in PreparedStatement.
    addBatch(String sql)inherited from Statement adds a new query to the batch of SQL statements for the statement. However you don't want to use this with PreparedStatements Instead you want
    addBatch()which adds the current set of parameters to the prepared statements batch of commands.
    In this scenario you prepare your query (insert statement) and then call setXXX(x,y) for each parameter and then addBatch for each tuple. Then call executeBatch to execute all the queries based on your batched parameters.
    If this didn't answer your question I don't know what your question is exactly. I would add that you probably want to set a "reasonable" size on your batches and break them into smaller batches as is reasonable. Mainly because the implementation of batched PreparedStatements widely varies depending on the database and driver, thus there are certainly scenarios where given enough batched parameters you could have various unpleasant things visited upon your program. Like terminal slowness, running out of memory, etc.

  • How to use prepared statement - For Everyone Help

    public String count()
    int count = 0;
    String fetchsize = "";
    try
    Connection conn = getOADBTransaction().getJdbcConnection();
    Statement statement = conn.createStatement();
    String Query = "select count(*) count from fnd_lookups where lookup_type like 'SAPE_BILL_TO_SHIP_TO_UPDATE'";
    ResultSet resultset = statement.executeQuery(Query);
    while (resultset.next())
    count = (int)resultset.getInt("count");
    fetchsize = ""+count;
    catch(Exception e)
    return fetchsize;
    }

    Hi,
    we can use prepare statement in Co....
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    try
    PreparedStatement prpdStmt1 = am.getOADBTransaction().getJdbcConnection().prepareStatement("select full_name from per_all_people_f where person_id='"+empid+"' ");
    ResultSet rs=prpdStmt1.executeQuery(); //Cursor fetch row
    while(rs.next())
    empname=rs.getString(1);
    catch(Exception e)
    System.out.println("Exception is"+e.getMessage());
    t1.setValue(pageContext,empname);
    Thanks
    nani

  • Using prepared statements in java

    Hi
    I have question on proper usage of prepared statements.
    PreparedStatement ps;
    public methoda(){
    ps=conn.prepareStatement(sqlQry);
    ps.setInt(1,2);
    ps.execute();
    In the above case I am creating new references to prepared statement (ps)each time I invoke methoda. So am I still using the advantage of prepared statements that is prepare a statement once and execute it multiple times. Or in the above case, the DB knows that this has been executed before and does not prepare it second time and just executes it.
    thanks

    The database stores execution plans for previous statements that were executed. So even tho you create a new PreparedStatement each time, it will still be an improvement.
    Even if you don't use prepared statements those plans are cached. Problem is that you must reuse the exact same sql to get the benefit.
    So if you do
    select password from users where user="dave";
    a hundred times, the database most likely will only create the plan once.
    Problem is of course, that
    select password from users where user="yelapa";
    is a completely different sql statement sofar as the database knows.
    Thus, the value of Prepared statements.
    select password from users where user=?
    is what the database sees no matter what user is running it.

  • Problem in inserting to MS Access using prepared statement

    I am inserting a record in MS Access db and I am using prepared statement. I am encountering an error.... any help I would really appreciate it. So much time figuring out what the problem is....
    ConvertText contxt = new ConvertText();
    String bday = (String)cbYear.getSelectedItem() +
    cbMonth.getItemCount()+(String)cbDay.getSelectedItem();
    try{
    // load MySQL driver
    Class.forName(driver);
    // Setup connection to DBMS
    Connection conn = DriverManager.getConnection(url);
    // Create statement     
    Statement stmt     = conn.createStatement();
    PreparedStatement insertPersons = conn.prepareStatement(
            "INSERT INTO PERSONS VALUES(" +
         "FIRST_NAME               = ?," +
         "LAST_NAME              = ?," +
         "MIDDLE_NAME               = ?," +
         "NICKNAME              = ?," +
         "GENDER              = ?," +
         "MARITALSTATUS           = ?," +
         "AGE                    = ?," +
         "BIRTHDATE                   = ?," +
         "ADDRESS                  = ?," +
         "RES_PHONE_NUMBER        = ?," +
         "OFFICE_PHONE_NUMBER     = ?," +
         "CELL_NUMBER               = ?," +
         "COMPANY_NAME               = ?," +
         "EMAIL_ADDRESS               = ?," +
         "TIMESTAMP               = ?)"
              insertPersons.setString   (1, tfFirstName.getText());
              insertPersons.setString   (2, tfLastName.getText());
              insertPersons.setString   (3, tfMiddleName.getText());
              insertPersons.setString   (4, tfNickName.getText());
              insertPersons.setString   (5, (String)cbGender.getSelectedItem());
              insertPersons.setString   (6, (String)cbMaritalStatus.getSelectedItem());
              insertPersons.setInt      (7, contxt.formatStringToInt(tfAge.getText()));
              insertPersons.setDate     (8, contxt.formatStringToSQLDate(bday));
              insertPersons.setString   (9, tfAddress.getText());
              insertPersons.setString   (10,tfResPhoneNumber.getText());
              insertPersons.setString   (11,tfOffPhoneNumber.getText());
              insertPersons.setString   (12,tfCellNumber.getText());
              insertPersons.setString   (13,tfCompanyName.getText());
              insertPersons.setString   (14,tfEmailAddress.getText());
              insertPersons.setTimestamp(15, new Timestamp(System.currentTimeMillis()));          
              insertPersons.executeUpdate();
              conn.close();          
    JOptionPane.showMessageDialog(null,"Record Inserted!", "INSERT",
                        JOptionPane.INFORMATION_MESSAGE);
    }catch (SQLException ex){
    System.err.println("==> SQLException: ");
    System.out.println("Message:   SQL Exception");
    System.out.println("Message:   " + ex.getMessage ());
    System.out.println("SQLState:  " + ex.getSQLState ());
    System.out.println("ErrorCode: " + ex.getErrorCode ());
    JOptionPane.showMessageDialog(null, ex.getMessage() + ex.toString(),"Error", JOptionPane.INFORMATION_MESSAGE);
    }catch(Exception ex){
    }          ERROR Displayed:
    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 30. java.sql.SQLException     

    Hi cruzdhel,
    Your SQL looks incorrect to me.
    I am not familiar with that syntax.
    I think it should be like this:
    PreparedStatement insertPersons =
    conn.prepareStatement("INSERT INTO PERSONS (FIRST_NAME," +
                                               "LAST_NAME," +
                                               "MIDDLE_NAME," +
                                               "NICKNAME," +
                                               "GENDER," +
                                               "MARITALSTATUS," +
                                               "AGE," +
                                               "BIRTHDATE," +
                                               "ADDRESS," +
                                               "RES_PHONE_NUMBER," +
                                               "OFFICE_PHONE_NUMBER," +
                                               "CELL_NUMBER," +
                                               "COMPANY_NAME," +
                                               "EMAIL_ADDRESS," +
                                               "TIMESTAMP)" +
    "values (?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?)");Hope this helps.
    Good Luck,
    Avi.

  • How to Insert Character using Prepared statement

    Hi All,
    Can anyone let me know how can I insert character using prepared statement.
    Thanks
    Sameer

    In the future JDBC related questions should be posted into the JDBC forum.
    Can you please provide some more information about what you are trying to do? It isn't clear to me. Are you trying to update a CHAR field?

  • When to use abstract class compared to interface

    hi
    can some one plase advise me when to use abstract class compared to interface?
    Example will be appreciated...

    So an abstract class can carry implementation. This can be used to formulate a rule of thumb as to when to use it over an interface.
    If you have a so called type specialization relationship between the subtypes and the supertype then they're likely to benefit from shared implementation provided by the supertype, so use class (abstract or concrete) extension in this case. Type specialization is when the supertype represents a general concept like Fruit and the subtypes are specialized forms of that like Apple and Banana.
    Another common kind of relationship is called type expansion. In this case the subtypes are unlikely to have any use of implementation provided by the supertype, so use interface implementation. Type expansion is when the supertype represents a specific character the subtypes take on. For example Apple and Bicycle ure unrelated in the type specialization sense but still can share a common character like Comparable. The subtypes have been expanded to include the supertype character, namely the ability to be compared.

  • Invalid cursor state error while executing the prepared statement

    hai friends,
    following code showing the invalid cursor state error while executing the second prepared statement.
    pls anyone help me
    String query = "select * from order_particulars where order_no=" + orderno + " order by sno";             psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);             rs1 = psmt1.executeQuery();             rs1.last();             intRowCount = rs1.getRow();             particularsdata = new Object[intRowCount][6];             rs1.beforeFirst();             if (intRowCount >= 1) {                 for (int i = 0; rs1.next(); i++) {                     particularsdata[0] = i + 1;
    particularsdata[i][1] = rs1.getString(3);
    particularsdata[i][2] = Double.parseDouble(rs1.getString(4));
    rs1.close();
    psmt1.close();
    query = "SELECT sum(delqty) FROM billdetails,billparticulars WHERE order_no= " + orderno + " and " +
    "billdetails.bill_no = billparticulars.bill_no GROUP BY particulars ORDER BY sno";
    psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs1 = psmt1.executeQuery(); //error showing while executing this line

    Also .. Why using arrays instead of collections? Shifting the cursor all the way forth and back to get the count is fairly terrible.
    With regard to the problem: either there's a nasty bug in the JDBC driver used, or you actually aren't running the compiled class version of the posted code.

  • Can not use prepared statement

    i am using a prepared statement for the following query but the query does not give me an output where as if i use a create statement i am getting my result
    can any one say why is it ? or what the problem is
                String strQuery = " select lic.lic_id  licId, "+                                                   " lic.license_nbr licNo, "+                                                   " lt.display_desc licType "+                                                   " from colamgr.cola_entities ent, "+                                                 " colamgr.cola_licenses lic, "+                                                 " colamgr.cola_lic_types lt, "+                                                 " colamgr.cola_boards    boa "+                                           " where (( 'E'= ? and ent.ent_id = ?) "+                                           " or ( 'L'= ? and lic.lic_id = ?)) "+                                           " and lic.ent_id = ent.ent_id "+                                           " and lic.license_status ='ACTIVE' "+                                           " and lic.lt_id = lt.lt_id "+                                           " and boa.boa_id = lt.boa_id "+                                           " and (( 'E' = ? and (lt.print_ent_addr_ind <> 'N' "+                                           " or (lt.print_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                           " or  ( 'L' = ? and lt.print_lic_addr_ind <> 'N')) "+                                           " UNION "+                                           " select  empl_lic.lic_id  licId, "+                                                   " empl_lic.license_nbr licNo, "+                                                   " empl_lt.display_desc licType "+                                                                                     " from colamgr.cola_entities  ent, "+                                                 " colamgr.cola_licenses  lic, "+                                                 " colamgr.cola_lic_types lt, "+                                                 " colamgr.cola_lic_xrefs lx, "+                                                 " colamgr.cola_licenses  empl_lic, "+                                                 " colamgr.cola_lic_types empl_lt, "+                                                 " colamgr.cola_boards    empl_boa "+                                           " where (( 'E'= ? and ent.ent_id = ?) "+                                           " or ( and lic.lic_id = ? and 'L'= ? )) "+                                           " and lic.ent_id              = ent.ent_id "+                                           " and lic.lic_id              = lx.lic_id "+                                           " and lic.license_status      ='ACTIVE' "+                                           " and lx.approval_ind        = 'A' "+                                           " and lx.begin_date          is not null "+                                           " and lx.end_date            is null "+                                           " and lx.lic_id_child        = empl_lic.lic_id "+                                           " and empl_lt.lt_id          = empl_lic.lt_id "+                                           " and empl_boa.boa_id        = empl_lt.boa_id "+                                           " and empl_lic.license_status = 'ACTIVE' "+                                           " and lic.lt_id              = lt.lt_id "+                                           " and exists (select 1 "+                                                       " from colamgr.cola_lic_types lt1 "+                                                       " where lt1.lt_id = empl_lic.lt_id "+                                                       " and ((lt1.xref1_ind in ('M') "+                                                       " and  lt1.xref1_lt_id = lt.lt_id "+                                                       " and  (('E'= ? and (lt1.print_xref1_ent_addr_ind <> 'N' "+                                                       " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                                       " or    ( 'L' = ? and lt1.print_xref1_lic_addr_ind <> 'N'))) "+                                                       " or  (lt1.xref2_ind in ('M') "+                                                       " and  lt1.xref2_lt_id = lt.lt_id "+                                                       " and  (('E'= ? and (lt1.print_xref2_ent_addr_ind <> 'N' "+                                                       " or (lt1.print_xref2_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                                       " or    ( 'L' = ? and lt1.print_xref2_lic_addr_ind <> 'N'))) "+                                                       " or  (lt1.xref1_ind in ('O') "+                                                       " and  (lt1.xref1_lt_id = lt.lt_id or lt1.xref2_lt_id = lt.lt_id) "+                                                       " and  (('E'= ? and (lt1.print_xref1_ent_addr_ind <> 'N' "+                                                       " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                                       " or    ('L' = ? and lt1.print_xref1_lic_addr_ind <> 'N'))))) "+                                                       " order by 6 desc, 7 asc ";

    here is my code which works . when i replace the ? ( where i am checking strAddrtype ='L' using set string it doesn't work . i wanted to know why its not working any help is much appreciated.
    thanks .
            public ArrayList getReprintLicenses(String strEntId, String strLicId, String strAddrType)
              ArrayList alMasterLicList = new ArrayList();
               String strQuery = " select lic.lic_id   licId, "+
                                                     " lic.license_nbr licNo, "+
                                                     " lt.display_desc licType, "+
                                                     " colamgr.COLA_CHK_RENEW_STAT(lic.lic_id) renewStatus, "+
                                                     " 0, "+
                                                     " SUBSTR(lic.License_nbr,1,4), "+
                                                     " SUBSTR(lic.License_nbr,5) "+
                                              " from cola_entities ent, "+
                                                   " cola_licenses lic, "+
                                                   " cola_lic_types lt, "+
                                                   " cola_boards    boa "+
                                              " where ((?= 'E' and ent.ent_id = ? ) "+
                                              " or ("+strAddrType+" = 'L' and lic.lic_id = ?)) "+
                                              " and lic.ent_id = ent.ent_id "+
                                              " and lic.license_status ='ACTIVE' "+
                                              " and lic.lt_id = lt.lt_id "+
                                              " and boa.boa_id = lt.boa_id "+
                                              " and ((?= 'E' and (lt.print_ent_addr_ind <> 'N' "+
                                              " or (lt.print_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                              " or   ("+strAddrType+" = 'L' and lt.print_lic_addr_ind <> 'N')) "+
                                              " UNION "+
                                              " select  empl_lic.lic_id  licId, "+
                                                      " empl_lic.license_nbr licNo, "+
                                                      " empl_lt.display_desc licType, "+
                                                      " COLA_CHK_RENEW_STAT(empl_lic.lic_id) renewStatus, "+
                                                      " 1, "+
                                                      " SUBSTR(lic.License_nbr,1,4), "+
                                                      " SUBSTR(lic.License_nbr,5) "+
                                              " from cola_entities  ent, "+
                                                   " cola_licenses  lic, "+
                                                   " cola_lic_types lt, "+
                                                   " cola_lic_xrefs lx, "+
                                                   " cola_licenses  empl_lic, "+
                                                   " cola_lic_types empl_lt, "+
                                                   " cola_boards    empl_boa "+
                                              " where ((? = 'E' and ent.ent_id =?) "+
                                              " or ("+strAddrType+" = 'L' and lic.lic_id =?)) "+
                                              " and lic.ent_id              = ent.ent_id "+
                                              " and lic.lic_id              = lx.lic_id "+
                                              " and lic.license_status      ='ACTIVE' "+
                                              " and lx.approval_ind         = 'A' "+
                                              " and lx.begin_date           is not null "+
                                              " and lx.end_date             is null "+
                                              " and lx.lic_id_child         = empl_lic.lic_id "+
                                              " and empl_lt.lt_id           = empl_lic.lt_id "+
                                              " and empl_boa.boa_id         = empl_lt.boa_id "+
                                              " and empl_lic.license_status = 'ACTIVE' "+
                                              " and lic.lt_id               = lt.lt_id "+
                                              " and exists (select 1 "+
                                                          " from cola_lic_types lt1 "+
                                                          " where lt1.lt_id = empl_lic.lt_id "+
                                                          " and ((lt1.xref1_ind in ('M') "+
                                                          " and  lt1.xref1_lt_id = lt.lt_id "+
                                                          " and  ((? = 'E' and (lt1.print_xref1_ent_addr_ind <> 'N' "+
                                                          " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                                          " or    (?= 'L' and lt1.print_xref1_lic_addr_ind <> 'N'))) "+
                                                          " or   (lt1.xref2_ind in ('M') "+
                                                          " and  lt1.xref2_lt_id = lt.lt_id "+
                                                          " and  ((?= 'E' and (lt1.print_xref2_ent_addr_ind <> 'N' "+
                                                          " or (lt1.print_xref2_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                                          " or    (? = 'L' and lt1.print_xref2_lic_addr_ind <> 'N'))) "+
                                                          " or   (lt1.xref1_ind in ('O') "+
                                                          " and   (lt1.xref1_lt_id = lt.lt_id or lt1.xref2_lt_id = lt.lt_id) "+
                                                          " and  ((? = 'E' and (lt1.print_xref1_ent_addr_ind <> 'N' "+
                                                          " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                                          " or    (? = 'L' and lt1.print_xref1_lic_addr_ind <> 'N'))))) "+
                                                          " order by 6 desc, 7 asc ";
              try
                con = getDSconn();
         //  stmt = con.createStatement();
              pstmt=con.prepareStatement(strQuery);
               // rs = stmt.executeQuery(strQuery);
            pstmt.setString(1,strAddrtype);
             pstmt.setString(2,strEntId);
             pstmt.setString(3,strLicId);
             pstmt.setString(4,strAddrtype);
             pstmt.setString(5,strAddrtype);
             pstmt.setString(6,strEntId);
             pstmt.setString(7,strLicId);
             pstmt.setString(8,strAddrtype);
             pstmt.setString(9,strAddrtype);
             pstmt.setString(10,strAddrtype);
             pstmt.setString(11,strAddrtype);
    pstmt.setString(12,strAddrtype);
    pstmt.setString(13,strAddrtype);
              rs=pstmt.executeQuery();
                while (rs.next())
                  LicenseeForm licenseInfo = new LicenseeForm();
                  licenseInfo.setLicId(rs.getString(1));
                  licenseInfo.setLicNo(rs.getString(2));
                  licenseInfo.setLicType(rs.getString(3));
                  //licenseInfo.setBoard(rs.getString(4));
                  licenseInfo.setRenewStatus(rs.getString(4));
                  alMasterLicList.add(licenseInfo);
                rs.close();
                pstmt.close();
                con.close();
                con = null;
              catch (RuntimeException re)
                    throw re;
              catch(Exception e)
              { e.printStackTrace();
                try
                  rs.close();
                  pstmt.close();
                  con.close();
                  con = null;
                catch(Exception i){}
              finally
                try
                  pstmt.close();
                  con.close();
                  con = null;
                catch(Exception i){}
              return alMasterLicList;     
           

  • Does a Database Control use Prepared Statements?

    When I add a method to a database control I have to supply the SQL for that method. Under the covers does the database control convert that SQL into a prepared statement? Is this documented anywhere?
    Thanks for the help!
    Rob

    Rob,
    it seems not be documented, but the Database Control always uses a PreparedStatement internally.
    -Kai

  • ? in SQL Queries and not using prepared statements

    Using EclipseLink 1.1.1
    Prepared Statements are disabled
    In our production server something went wrong and one of our Read Queries started erroring. A DatabaseException was thrown and we log the "getQuery.getSQLString()" statement. We found this query in the logs:
    SELECT t1.ID, t1.NAME, t1.DESCRIPTION, t1.EXTREFID, t1.STYLESHEET, t1.DDSVNVERSION, t1.FIRSTNAME, t1.LASTNAME, t1.EMAILADDR, t1.PHONENUMBER, t1.ADDRESS, t1.ADDRESS2, t1.CITY, t1.STATE, t1.POSTALCODE, t1.COUNTRY, t1.ADMINACCTNAME, t1.HASDOCUMENTS, t1.HASTIMEDNOTIFICATIONS, t1.STATUS, t1.ENTRYDATE, t1.EVALEXPDATE, t1.LASTREMINDDATE, t1.FULLUSERS, t1.LIMUSERS, t1.REQUSERS, t1.ISENTERPRISE, t1.EXPDATE, t1.ISDISABLED, t1.DISABLEDDATE, t1.NEEDLICENSEAGREEMENT, t1.ISWARNINGDISABLED, t1.LOCALE, t1.TIMEZONE, t1.CURRENCY, t1.DOMAIN, t1.DOCUMENTSIZE, t1.EXTRADOCUMENTSTORAGE, t1.ONDEMANDOPTIONS, t1.SSOTYPE, t1.RESELLERID, t1.ACCOUNTREPID, t1.LASTUSAGEREPORTDATE, t1.NEXTUSAGEREPORTDATE, t1.USAGEREPORTATTEMPTS FROM T_SSOOPTIONS t0, T_CUSTOMERS t1 WHERE *((((t0.SSOENABLED = ?) AND (t1.SSOTYPE IN (?, ?))) AND (UPPER(t1.DOMAIN) = ?)) AND (t0.CUSTOMERID = t1.ID))*
    Notice the values weren't entered into the where clause. We had to bounce the application to fix the problem. I've never seen this before. I've added more debugging statements to the code - so if this happens again in the future I'll have more information to report on. In the mean time I'm wondering if anyone else has every seen a problem of this nature.

    Database error due to invalid SQL statement.
    I don't have a stack, we were catching the exception and not printing the stack :(
    Like I mentioned in my first post, I added more debugging code (e.printStackTrace()). I understand this is hard to track down without more information. I was just hoping you guys had seen something like this before and had any insight. Like I mentioned before: this is on our production server. I've never seen this type of error before. That particular server (we run in a cluster mode) had been up for several days and then started generating that error. IT bounced the node and everything went back to normal. We have been using toplink for about 5 years now and have never seen this problem, until August 3rd 2009. The only thing that has changed recently is our migration from toplink 10 to EclipseLink. I was wondering if anyone knows if anything had changed in EclipseLink/toplink 11 with the generation of SQL queries.
    I'll keep looking. There is more debugging code in there now. Since the error was "Database error due to invalid SQL statement" this implies the SQL was generated, exited that part of the code and was sent to the db where it failed. I'm afraid the printStackTrace won't help if this error happens again.

  • SQL query slow when issued by app, fast when issued mnaually

    Hi there,
    I have a more general question about a specific Oracle behaviour.
    I update a feature from within an application. The application doesn't respond and I finally have to terminate it. I checked Oracle whether a query is running long using the following statement:
    select s.username,s.sid,s.serial#,s.last_call_et/60 mins_running,q.sql_text from v$session s
    join v$sqltext_with_newlines q
    on s.sql_address = q.address
    where status='ACTIVE'
    and type <>'BACKGROUND'
    and last_call_et> 60
    order by sid,serial#,q.piece
    The result of the above query is:
    WITH CONNECTION AS ( SELECT * FROM WW_CONN C WHERE (C.FID_FROM I
    N (SELECT FID FROM WW_LINE WHERE FID_ATTR=:B1 ) AND C.F_CLASS_ID
    FROM =22) OR (C.FIDTO IN (SELECT FID FROM WW_LINE WHERE FID_AT
    TR=:B1 ) AND C.F_CLASS_ID_TO =22) ) SELECT MIN(P.FID_ATTR) AS FI
    D_FROM FROM CONNECTION C, WW_POINT P WHERE (P.FID = C.FID_FROM A
    ND C.F_CLASS_ID_FROM = 32 AND C.FLOW = 1) OR (P.FID = C.FID_TO A
    ND C.F_CLASS_ID_TO = 32 AND C.FLOW = 2)
    I have a different tool which shows me the binding parameter values. So I know that the value for :B1 is 5011 - the id of the feature being updated. This query runs for 20 mins and longer before it eventually stops. The update process involves multiple sql statements - so this one is not doing the update but is part of the process.
    Here is the bit I do not understand: when I run the query in SQL Developer with value 5011 for :B1 it takes 0.5 secs to return a result.
    Why is it, that the sql statement takes so long when issued by the application but takes less than a second when I run it manually?
    I sent a dump of the data to the application vendor who is not able to reproduce the issue in their environment. Could someone explain to me what happens here or give me some keywords for further research?
    We are using 11gR2, 64bit.
    Many thanks,
    Rob

    Hi Rob,
    at least you should see some differences in the statistics for the different child cursor (the one for the execution in the application should show at least a higher value for ELAPSED_TIME). I would use something like the following query to check the information for the child cursors:
    select sql_id
         , PLAN_HASH_VALUE
         , CHILD_NUMBER
         , EXECUTIONS
         , ELAPSED_TIME
         , USER_IO_WAIT_TIME
         , CONCURRENCY_WAIT_TIME
         , DISK_READS
         , BUFFER_GETS
         , ROWS_PROCESSED
      from v$sql
    where sql_id = your_sql_idRegards
    Martin

Maybe you are looking for