PreparedStatement and "in" clause

I am trying to pass an "in" clause to a SQL statement as a bind variable, but keep getting an "invalid number" runtime error:
The "where" clause of the SQL statement is:
String wherestmnt = "where sh.header_id in ? ";
I am using a PreparedStatement and am setting the bind variable as follows:
pstmt.setString(1,"(34552)")
If I change the "in" clause to "=" and do a set as pstmt.setString(1,"34552") it works fine.
Any advice?
null

There is also another error. If you need to use the in clause the values must be within paranthesis,
So if your query were like,
select * from emp where empno in (?)
then the bind would work. You can have as many ? as you want separated by commas and you can bind that many values..!

Similar Messages

  • PreparedStatements and LIKE clauses

    Hi,
    I've come across a slight problem with PreparedStatements and LIKE clauses. Say I want my query to look something like this:
    SELECT * FROM CONTENT_TABLE WHERE CONTENT LIKE '%test%'If I were to use a PreparedStatement I'd do something like this:
    PreparedStatement searchContent = con.prepareStatement("SELECT * FROM CONTENT_TABLE WHERE CONTENT LIKE ?");
    searchContent.setString(1, queryString);This isn't correct becuase it matches where CONTENT LIKE 'queryString'
    I tried this:
    PreparedStatement searchContent = con.prepareStatement("SELECT * FROM CONTENT_TABLE WHERE CONTENT LIKE '%?%'");
    searchContent.setString(1, queryString);But I get a syntax error in my SQL.
    Is there another way around this?
    Thanks

    just guessing try this:
    PreparedStatement searchContent = con.prepareStatement("SELECT * FROM CONTENT_TABLE WHERE CONTENT LIKE '%?%'");searchContent.setString(1, "%"+queryString+"%");
    This might work, since ? gets replaced by '...', so i am guessing %..% will fit..
    give it a shot, i might be wrong.

  • PreparedStatement with IN clause

    Hi,
    I have a question regarding using a PreparedStatement and a query
    using an IN clause.
    I need to pass an array of values to using an IN clause. How does the
    binding work in this case since I am getting an SQLException - Invalid
    column type ?
    I need to pass an array of longs to this query.
    The java.sql.Array does not have an implementation. How does this do
    this ?

    Aswin Dinakar wrote:
    >
    Thanks a lot ! You really understood my problem without me describing it
    properly.
    I dont mind keeping it as a statement but that statement is being executed in
    a FOR loop thousands of times and its a very complex SQL with lots of joins
    and its taking up a lot of the CPU. Time constraint prevent me from changing
    the business logic.I also suggest making a stored procedure to do the complex stuff. At least the
    DBMS will only have to parse it once. The argument could even be a string
    like "1,2,3,4,5,6", and the procedure could handle separating the values.
    In a related issue do you know if the JMS database updates(deletes mostly) for
    WLS 5.1 are PreparedStatement(s) ? When I query the v$sqlarea table for the
    parse counts I see lots of JMS updates to the database.yes they are, but our MS SQLServer driver is inefficient about SQL with
    PreparedStatements, sending fresh SQL to be parsed each execution. I suggest
    your trying the MS driver from www.inetsoftware.de, which will do a better jod
    than ours in this area.
    Joe
    >
    Joseph Weinstein wrote:
    A PreparedStatement only allows settable parameters representing
    single values. You can't do:
    stmt = c.prepareStatement("select * from foo where key in ?");
    stmt.setString(1, "(1,2,3,4,5,6)");
    Therefore, you need to know how many values in your In clause,
    and generate a PreparedStatement like:
    stmt = c.prepareStatement("select * from foo where key in (?,?,?,?,?...");
    with a '?' for every value. Depending on whose driver your using, and
    whether you can keep and re-use PreparedStatments, it might be better
    to simply make the whole SQL query as a simple string and execute it:
    String query = "select * from foo where key in (1,2,3,4,5,6)";
    rs = stmt.executeQuery(query);
    Aswin Dinakar wrote:
    Hi,
    I have a question regarding using a PreparedStatement and a query
    using an IN clause.
    I need to pass an array of values to using an IN clause. How does the
    binding work in this case since I am getting an SQLException - Invalid
    column type ?
    I need to pass an array of longs to this query.
    The java.sql.Array does not have an implementation. How does this do
    this ?

  • Error while using REMAP_TABLE and WHERE clause  together in IMPDP

    I am trying to move some records from a very large table to another small table.
    I am facing trouble while using REMAP_TABLE and WHERE clause together in IMPDP.
    Problem is data filter is not getting applied and all records are getting imported.
    here is how I have simulated this. please advice.
    CREATE TABLE TSHARRHB.TMP1
      A  NUMBER,
      B  NUMBER
    begin
    Insert into TSHARRHB.TMP1
       (A, B)
    Values
       (1, 1);
    Insert into TSHARRHB.TMP1
       (A, B)
    Values
       (2, 2);
    COMMIT;
    end;
    expdp system/password TABLES=tsharrhb.TMP1 DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp REUSE_DUMPFILES=YES LOGFILE=EXP.log PARALLEL=8
    impdp system/password DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY='TSHARRHB.TMP1:"WHERE TMP1.A = 2"'  REMAP_TABLE=TSHARRHB.TMP1:TMP3 CONTENT=DATA_ONLY
    Import: Release 11.2.0.1.0 - Production on Fri Dec 13 05:13:30 2013
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, Automatic Storage Management, OLAP, Data Mining
    and Real Application Testing options
    Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/********@GRD6.RBSG DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp LOGFILE=SSD_93_TABLES_FULL_EXP.log PARALLEL=8 QUERY=TSHARRHB.TMP1:"WHERE TMP1.A = 2" REMAP_TABLE=TSHARRHB.TMP1:TMP3 CONTENT=DATA_ONLY
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "TSHARRHB"."TMP3"                           5.421 KB       2 rows
    Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 05:13:33
    here I am expecting only 1 record to get imported but both the records are getting imported. please advice.

    The strange thing compared to your output is that I get an error when I have table prefix in the query block:
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY=SYSADM.TMP1:"WHERE TMP1.A = 2" REMAP_TABLE=SYSADM.TMP1:TMP3 CONTENT=DATA_ONLY
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    ORA-31693: Table data object "SYSADM"."TMP3" failed to load/unload and is being skipped due to error:
    ORA-38500: Unsupported operation: Oracle XML DB not present
    Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Fri Dec 13 10:39:11 2013 elapsed 0 00:00:03
    And if I remove it, it works:
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY=SYSADM.TMP1:"WHERE A = 2" REMAP_TABLE=SYSADM.TMP1:TMP3 CONTENT=DATA_ONLY
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "SYSADM"."TMP3"                             5.406 KB       1 out of 2 rows
    Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Fri Dec 13 10:36:50 2013 elapsed 0 00:00:01
    Nicolas.
    PS: as you can see, I'm on 11.2.0.4, I do not have 11.2.0.1 that you seem to use.

  • What's the difference between "PreparedStatement" and "Statement"?

    What's the difference between "PreparedStatement" and "Statement"?
    Which is better??????

    Read the docs for the two classes. The differences are apparent there.
    Which one is better depends on your needs. I think that constructing and executing a PreparedStatement can be a bit less performant than just a Statement, if you're only executing the query one time. But I don't think that difference will normally be noticable in the context of a given application.
    Additionally, if you have to pass any dates or strings to the query, you'll want PreparedStatement's parameters, rather than trying to format and escape things in the query string.

  • Which two statements are true about WHERE and HAVING clause ?

    Which two statements are true about WHERE and HAVING clause ?
    1. WHERE clause can be used to restict rows only
    2.HAVING clause can be used to restrict groups only
    3.HAVING clause can be used to restrict groups and rows
    Plz help me in dis ques...which two will be correct...i think its 1 and 2...but not sure.

    863180 wrote:
    Plz help me in dis ques...which two will be correct...i think its 1 and 2...but not sure.If you are not sure then you do not fully understand HAVING.
    SY.

  • Qualifying Expression and WHERE CLAUSE Extension

    I would like to know the exact difference between 'Qualifying Expression and WHERE CLAUSE Extension'. Since both are meant to contain some CONDITION that would facilitate the Edit Check's success, So I am sometimes a bit confused with these too as to when to use what.
    Can someone help Please??

    As you can tell from my previous posts (requests!) - I'm a newbie to OC.
    From the documentation - it appears that both Qualifying expression and Where Clause work the same way but the way they execute is different.
    Qualifying expression is applied after the fetch (key fields and question response data from DCM cursor i.e., after the cursor fetches the data) and Where clause filters before QG fetch.
    HTH

  • Using PreparedStatement and the Oracle Error ORA-1000

    Hi,
    I have a question about PreparedStatement objects that is not so simple to explain for me. What I would like to know is: if I use a PreparedStatement following traditional and generic steps:
    1- PreparedStatement pStmt = Connection.prepareStatement(sQuery);
    2- pStmt.setXXX(i,j);
    n - pStmt.setXXX(i,j);
    n+1 - ResultSet rs = pStmt.executeQuery();
    n+2 - while(rs.next()){ ... retrive ResultSet data  ... }
    n+3 - rs.close()
    n+4 - back to point number 2
    and at the end (as you can see in the point numbered n+4), instead of closing the PreparedStatement pStmt using the close() method, I reuse the PreparedStatement pStmt comeing back to the point numebr 2 and setting again all its parameters with new values ... then ... what heppens in the Oracle database ? Has been the cursor (so the mamory area), associated to my PreparedStatement object pStmt, duplicated or is it the same ?
    I know that Java allows you to do this kind of operations with PreparedStatement, and I know that in tha Java Documentation is explained to follow this strategy to optimize the execution time because in this way the same PreparedStatement is precompiled and prepared only once. But if I do a for loop following the steps explained before, after many iterations I have the error "ORA-1000: maximum open cursors exceeded". This error is the reason of my question. Does this error means that it's mandatory to close a PreparedStatement always, otherwise if you reuse it without closing it then the corresponding database cursor will be duplicated ? If it is so, then I think this is a contradiction with official java documentation ...
    I'm using Oracle8i (version 8.1.7) and Oracle JDBC Thin Driver (Windows NT) for use with JDK 1.2.x. Moreover, in my database istance the parameter "maximum open cursor" is equal to 800 ...
    Thank you very much for suggestions :-)

    There is no need to close a prepared statement or its resultset for every iteration.
    After the first iteration in a loop, all subsequent executions of it will close the previous resultset. By adding close() method, you are making one extra costly call to the DB for no reason.
    Following is the sample code.I know what you are saying. In fact at the beginning I wrote my code in the same way of your sample (see the code of my first post at the begin of this page).
    But doing so, after thousand iterations of the loop, I had "Oracle Error ORA-1000 : maximun open cursor exeeded" even if in my database istance the parameter "maximum open cursor" is equal to 8000.
    At this moment in my code, for each iteration, I close the PreparedStatement and in this way I don't have anymore the error :-((
    So it seems that only in theory we can reuse a preparedStatement without closing it. In fact if we see the oracle system table "$open_cursor" (as Konrad Pietzka suggest me) we can find that, for each interation,
    at our line code "rs = pstmt.executeQuery();" correspond a new cursor in the database: this means that for each method "pstmt.executeQuery()" the database open a new cursor and do not use the previous one as it should.
    I posted a question two months ago to search if someone had the same problem (it seems that Konrad Pietzka had the same situation) and was able to explain me what is the cause.
    The only reason I found by myself for this problem, is that probably the Oracle JDBC Thin Driver for Windows NT/2000 has some bugs... but I'm not sure ...
    Thank you very much for you time !!
    bye :-))
    Fidalma

  • Use of Where and having clause

    Hi all,
    I always have a doubt about use of HAVING and WHERE clause,
    suppose I have table T1 with only one column C1
    CREATE TABLE T1
    (C1 VARCHAR2(1) );
    which having data by following INSERT scripts
    INSERT INTO T1 VALUES('A');
    INSERT INTO T1 VALUES('B');
    INSERT INTO T1 VALUES('C');
    INSERT INTO T1 VALUES('A');
    INSERT INTO T1 VALUES('B');
    INSERT INTO T1 VALUES('A');
    Now I want result as follows
    C1 ==== COUNT(C1)
    ==============
    B ===== 2
    A ===== 3
    So out of query 1 and 2 which approach is right ?
    1) SELECT C1,COUNT(C1) FROM T1
    WHERE C1<>'C'
    GROUP BY C1
    ORDER BY C1 DESC;
    2) SELECT C1,COUNT(C1) FROM T1
    GROUP BY C1
    HAVING C1<>'C'
    ORDER BY C1 DESC;
    Edited by: user13306874 on Jun 21, 2010 2:36 AM

    In SQL, it's always best to filter data at the earliest moment possible.
    In your example the WHERE clause would be that moment:
    SQL> explain plan for
      2  select c1,count(c1)
      3  from t1
      4  where c1 != 'C'
      5  group by c1
      6* order by c1 desc;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3946799371
    | Id  | Operation          | Name | Rows  | Bytes |
    |   0 | SELECT STATEMENT   |      |     5 |    10 |
    |   1 |  SORT GROUP BY     |      |     5 |    10 |
    |*  2 |   TABLE ACCESS FULL| T1   |     5 |    10 |
    Predicate Information (identified by operation id):
       2 - filter("C1"!='C')
    18 rows selected.
    SQL>As you can see the filter is applied during the scan of T1.
    Whereas in the HAVING case:
    SQL> explain plan for
      2  select c1,count(c1)
      3  from t1
      4  group by c1
      5  having c1 != 'C'
      6* order by c1 desc;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3146800528
    | Id  | Operation           | Name | Rows  | Bytes |
    |   0 | SELECT STATEMENT    |      |     6 |    12 |
    |*  1 |  FILTER             |      |       |       |
    |   2 |   SORT GROUP BY     |      |     6 |    12 |
    |   3 |    TABLE ACCESS FULL| T1   |     6 |    12 |
    Predicate Information (identified by operation id):
       1 - filter("C1"!='C')
    18 rows selected.
    SQL>The scan is done after all groups have been computed: one of which was computed in vain, since it will be filtered away due to the HAVING clause.
    In general I would use as a guideline: if you are not using aggregate functions in your HAVING clause predicate, then move that predicate to the WHERE portion of your query.
    Edited by: Toon Koppelaars on Jun 21, 2010 11:54 AM

  • Execution of subquery of IN and EXISTS clause.

    Hi Friends,
    Suppose we have following two tables:
    emp
    empno number
    ename varchar2(100)
    deptno number
    salary number
    dept
    deptno number
    location varchar2(100)
    deptname varchar2(100)
    status varchar2(100)
    Where dept is the master table for emp.
    Following query is fine to me:
    SELECT empno, ename
    FROM emp,dept
    WHERE emp.deptno = dept.deptno
    AND emp.salary &gt;=5000
    AND dept.status = 'ACTIVE';
    But I want to understand the behaviour of inline query (Used with IN and EXISTS clause) for which I have used this tables as an example (Just as Demo).
    1)
    Suppose we rewrite the above query as following:
    SELECT empno, ename
    FROM emp
    WHERE emp.salary &gt;=5000
    AND deptno in (SELECT deptno FROM dept where status = 'ACTIVE')
    Question: as shown in above query, suppose in our where clause, we have a condition with IN construct whose subquery is independent (it is not using any column of master query's resultset.). Then, will that query be executed only once or will it be executed for N number of times (N= number of records in emp table)
    In other words, how may times the subquery of IN clause as in above query be executed by complier to prepared the subquery's resultset?
    2)
    Suppose the we use the EXISTS clause (or NOT EXISTS clause) with subquery where, the subquery uses the field of master query in its where clause.
    SELECT E.empno, E.ename
    FROM emp E
    WHERE E.salary &gt;=5000
    AND EXISTS (SELECT 'X' FROM dept D where status = 'ACTIVE' AND D.deptno = E.deptno)
    Here also, I got same confusion. For how many times the subquery for EXISTS will be executed by oracle. For one time or for N number of times (I think, it will be N number of times).
    3)
    I know we can't define any fix thumbrule and its highly depends on requirement and other factors, but in general, Suppose our main query is on heavily loaded large transaction table and need to check existance of record in some less loaded and somewhat smaller transaction table, than which way will be better from performance point of view from above three. (1. Use of JOIN, 2. Use of IN, 3. Use of EXISTS)
    Please help me get solutions to these confusions..
    Thanks and Regards,
    Dipali..

    Dipali,
    First, I posted the links with my name only, I don;t know how did you pick another handle for addressing it?Never mind that.
    >
    Now another confusion I got.. I read that even if we used EXISTS and , CBO feels (from statistics and all his analysis) that using IN would be more efficient, than it will rewrite the query. My confusion is that, If CBO is smart enough to rewrite the query in its most efficient form, Is there any scope/need for a Developer/DBA to do SQL/Query tuning? Does this means that now , developer need not to work hard to write query in best menner, instade just what he needs to do is to write the query which resluts the data required by him..? Does this now mean that now no eperts are required for SQL tuning?
    >
    Where did you read that?Its good to see the reference which says this.I haven't come across any such thing where CBO will rewrite the query like this. Have a look at the following query.What we want to do is to get the list of all teh departments which have atleast one employee working in it.So how would be we write this query? Theremay be many ways.One,out of them is to use distinct.Let's see how it works,
    SQL> select * from V$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    SQL> set timing on
    SQL> set autot trace exp
    SQL> SELECT distinct  D.deptno, D.dname
      2        FROM     scott.dept D,scott.emp E
      3  where e.deptno=d.deptno
      4  order by d.deptno;
    Elapsed: 00:00:00.12
    Execution Plan
    Plan hash value: 925733878
    | Id  | Operation                     | Name    | Rows  | Bytes | Cost (%CPU)| T
    ime     |
    |   0 | SELECT STATEMENT              |         |     9 |   144 |     7  (29)| 0
    0:00:01 |
    |   1 |  SORT UNIQUE                  |         |     9 |   144 |     7  (29)| 0
    0:00:01 |
    |   2 |   MERGE JOIN                  |         |    14 |   224 |     6  (17)| 0
    0:00:01 |
    |   3 |    TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 0
    0:00:01 |
    |   4 |     INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 0
    0:00:01 |
    |*  5 |    SORT JOIN                  |         |    14 |    42 |     4  (25)| 0
    0:00:01 |
    |   6 |     TABLE ACCESS FULL         | EMP     |    14 |    42 |     3   (0)| 0
    0:00:01 |
    Predicate Information (identified by operation id):
       5 - access("E"."DEPTNO"="D"."DEPTNO")
           filter("E"."DEPTNO"="D"."DEPTNO")
    SQL>
    SQL> SELECT distinct  D.deptno, D.dname
      2        FROM     scott.dept D,scott.emp E
      3  where e.deptno=d.deptno
      4  order by d.deptno;
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
    Elapsed: 00:00:00.04
    SQL>So CBO did what we asked it do so.It made a full sort merge join.Now there is nothing wrong in it.There is no intelligence added by CBO to it.So now what, the query looks okay isn't it.If the answer is yes than let's finish the talk here.If no than we proceed further.
    We deliberately used the term "atleast" here.This would govern that we are not looking for entirely matching both the sources, emp and dept.Any matching result should solve our query's result.So , with "our knowledge" , we know that Exist can do that.Let's write teh query by it and see,
    SQL> SELECT   D.deptno, D.dname
      2        FROM     scott.dept D
      3          WHERE    EXISTS
      4                 (SELECT 1
      5                  FROM   scott.emp E
      6                  WHERE  E.deptno = D.deptno)
      7        ORDER BY D.deptno;
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
    Elapsed: 00:00:00.00
    SQL>Wow, that's same but there is a small difference in the timing.Note that I did run the query several times to elliminate the physical reads and recursive calls to effect the demo. So its the same result, let's see the plan.
    SQL> SELECT   D.deptno, D.dname
      2        FROM     scott.dept D
      3          WHERE    EXISTS
      4                 (SELECT 1
      5                  FROM   scott.emp E
      6                  WHERE  E.deptno = D.deptno)
      7        ORDER BY D.deptno;
    Elapsed: 00:00:00.00
    Execution Plan
    Plan hash value: 1090737117
    | Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Ti
    me     |
    |   0 | SELECT STATEMENT             |         |     3 |    48 |     6  (17)| 00
    :00:01 |
    |   1 |  MERGE JOIN SEMI             |         |     3 |    48 |     6  (17)| 00
    :00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 00
    :00:01 |
    |   3 |    INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 00
    :00:01 |
    |*  4 |   SORT UNIQUE                |         |    14 |    42 |     4  (25)| 00
    :00:01 |
    |   5 |    TABLE ACCESS FULL         | EMP     |    14 |    42 |     3   (0)| 00
    :00:01 |
    Predicate Information (identified by operation id):
       4 - access("E"."DEPTNO"="D"."DEPTNO")
           filter("E"."DEPTNO"="D"."DEPTNO")Can you see a keyword called Semi here? This means that Oralce did make an equi join but not complete.Compare the bytes/rows returned from this as well as cost with the first query.Can you notice the difference?
    So what do we get from all this?You asked that if CBO becomes so smart, won't we need developers/dbas at that time?The answer is , what one wants to be, a monkey or an astranaut? Confused,read this,
    http://www.method-r.com/downloads/doc_download/6-the-oracle-advisors-from-a-different-perspective-karen-morton
    So it won't matter how much CBO would become intelligent, there will be still limitations to where it can go, what it can do.There will always be a need for a human to look all the automations.Rememember even the most sofisticated system needs some button to be pressed to get it on which is done by a human hand's finger ;-).
    Happy new year!
    HTH
    Aman....

  • PreparedStatement and bind variable

    We are experiencing some werid performance break downs where database server looks healthy and our java applications are down to their knees.
    I was wondering if someone could help me clarify the comparison between PreparedStatement and bind variable. When I execute a PreparedStatement in java through the JDBC thin driver, would the database consider it a dynamic SQL or is it a SQL using bind variable? If this same statement is executed 100000 times, is it parsed 100000 times? We are using JDK131. How does it work?
    Is there any memory leak in PreparedStatement implementation in JDBC thin driver? Is there any known symptom to this problem? What is the recommended solution?
    Thank you very much!

    If PreparedStatement is parsed and cached, why is there setting to set implicit statement caching and explicit statement caching? Our DBA insists that it is parsed every single time. How would I find out for sure?
    The SQLs have not been changed. This sudden performance degradation started when a new client went live and we experienced higher than usual volumn. We are connecting using JDBC thin client from weblogic server to Oracle 8.1.7. It's been happening everyday since the client went live and the only way to get the performance back is to shutdown and restart the database server.
    I tried to search JDBC related issues. The only complain that I've found so far is that there may be some potential memory leak for a PreparedStatement. However, I have not found anything from Oracle's website that concurs to that.
    What is my best bet?

  • PreparedStatement and batchExecute

    Hi,
    I am trying to use PreparedStatement and batchExecution for inserting a few rows into database. I am using JTurbo driver.
    But it only inserts the last set of values. For Example
    Class.forName( "com.ashna.jturbo.driver.Driver" );
    Connection con = DriverManager.getConnection( "jdbc:JTurbo://server","username","password" );
    PreparedStatement pstm = con.prepareStatement( "INSERT INTO Test( ids, age, wt ) VALUES(?,?,?)" );
    int ids[] = {1000,1001,1002,1003};
    String[] age = { "12","13","14","15" };
    String[] wt = { "45","46","47","48" };
    for( int i=0 ; i<ids.length ; i++ )
    pstm.setInt( 1, ids[i] );     
    pstm.setString( 2, age[i] );
    pstm.setString( 3, wt[i] );     
    pstm.addBatch();
    int[] rows = pstm.executeBatch();
    pstm.clearBatch();
    con.close();
    In database, it shows
    1003, 15, 48
    1003, 15, 48
    1003, 15, 48
    1003, 15, 48
    Pls..pls..help me with this...i'm having a hard time figuring out this problem.. :(
    Thanks a lot...

    Maybe you just wrote this short-hand but if not try this:
    pstm.setInt( 1, ids[i] );
    pstm.setString( 2, age[i] );
    pstm.setString( 3, wt[i] );
    //...........

  • Database Procedure Calling by Using PreparedStatement and CallableStatement

    Hi
    We can execute Database Stored Procedure by using PreparedStatement and CallableStatement as well.Then what is the significance of having CallableStatement.
    Please let me know the difference between these two Statement objects particularly in Stored Procedures Execution.
    Thanks in advance
    Basha007

    A callable statement excecutes a stored procedure that's stored and run on the database server.
    A prepared statement doesn't require a database stored procedure. It's parsed and cached by the JDBC driver, and allows you to specify parameters and bind values to them at runtime. Those are usually used in loop constructs where you want to repeatedly execute the same SQL with different values.
    Not all RDBMS support stored procedures (e.g., MySQL), but every driver I've used allows PreparedStatements. - MOD

  • To Joe Schell - jschell... - PreparedStatement and executeBatch()

    Hi,
    Thanks for the reply to the PreparedStatement and executeBatch() query. Is there any workaround for it other than using the Statement object?
    thanks,
    Nish

    Could be.
    But since I have no idea about what you are talking about, I can't really comment.
    I respond to between 10-30 threads a day and read more than that. Consequently I need a context to understand questions.
    If I have previously (recently) responded to a previous thread then if you post a response to it I will generally see it in less than a day. If is an older thread you might want to start a new thread. But if you do then add a link or put enough content so I can follow it.

  • Record Group and From-Clause Datasource

    I need to do several complex queries (read-only) for my form. Original I used From-Clause datasource but, as the requirement changed, there are some limitations. I would rather no do anything dynamically if as all possible because there are over 20 such queries which makes the code difficult to maintain. I wanted to be able to reference block items in the query.
    I'm thinking about using Record Group query instead. What are the differences in capability between Record Groups and From-Clause Datasource?
    Thanks.
    Clayton.

    Thanks.
    That's exactly the problem I have. I don't want to use LOVs so I've been thinking about how to visualize the record group data using data blocks. Perhaps I'll just go with dynamically building the From-Clause.
    I've looked into stored procedure based blocks a bit; it was confusing for me. Are the stored procedures stored in the database or are they defined in the form?

Maybe you are looking for

  • Question on text message notifications with imessage open vs closed with  iOS7

    Before the upgrade to iOS7.1 when I received a text message my phone would vibrate both when the application was closed to nofify me of the message and when the application is open (I am looking at the text message) and then when another text would c

  • Question RE: Security/Virus Program for Macbook Pro

    Greetings, I was wondering if you would recommend Avast 2014 Antivirus Software protection for the macbook pro. If not, is there any other programs and/or other applications I should know about or use to help with viruses and security? I was also con

  • Passing table from ABAP to webservice using SOAP

    Hello: I am trying to pass table data from ABAP code to a webservice using SOAP.  I have seen many examples of passing single value parameters such as:   DATA: osoap   TYPE REF TO CSoapDocument.     GET REFERENCE OF p_refno INTO dref.     CALL METHOD

  • Calculations in ALV Tree

    Hi folks, I've done a report with an ALV TREE (CL_GUI_ALV_TREE) and I want to get on the first node the totals of its children. I have used the method UPDATE_CALCULATIONS and FRONT_END_UPDATE, everything it's ok when displaying the values, but when I

  • AIR 2.7.1: Help with sound stuttering problem in IOS!

    Hi all, I need to play audio in the background but unfortunately, it came out unstable: - On the 1st run after installing, it'll play fine until it loops, that's when the audio goes out completely. - On subsequent runs, the audio plays and loops but