Prepared statement with placeholders - the order or the names are important

Hi,
I'll explain my question, using the example from the OCCI documentation.
What if I do something like:
<pre>
// note the order
stmt->setSQL("BEGIN countFruit(:2, :1); END:");
stmt->setString(1, "Apples");
stmt->setString(2, "Oranges");
</pre>
This will become
<pre>
BEGIN countFruit( 'Apples', 'Oranges' ); END
</pre>
or
<pre>
BEGIN countFruit( 'Oranges', 'Apples' ); END
</pre>
So, if the answer is:
* *"the first one is correct"*, then - may I use whatever I want for placeholders (some strings, for example), just starting with ':' ?
* *"the second one is correct"*, then:
* * does this mean, that I can't use strings as placeholders (because setXXX does not take strings as first parameter, but a number - as position)
* * should I use consequent numbers, or I may use whatever I want. I mean, is this valid: "BEGIN countFruit(:13, :666); END:". So, if it is, does this mean, that I should use setXXX( 13, ...) and setXXX( 666, ...), instead of setXXX(1, ...) and setXXX(2, ...) ?
Sorry for the dummy questions, but I didn't see this explained in the doc (at least for 10g). And yes, I can test it, but this doesn't mean anything, it may be undefined behavior or server configuration, or whatever and I just want to be sure :)
Thanks in advance.
Best Regards,
Kiril Kirov

Looks like I have missed that.
I'm not sure I understand the difference, when using SQL and PL/SQL. Here's what I get, please correct me if I'm wrong:
For PL/SQL (for example - SP call), if I have
<pre>
BEGIN stored_procedure( :11, :22, :22, :33 ); END
</pre>
calling
<pre>
stmt->setString(3, "Apples");
</pre>
will set *"the third unique parameter"* - in this example, will replace ':33', right?
If so, will executing
<pre>
stmt->setString(2, "Oranges");
</pre> replace both ':22' placeholders?
And for standard SQL query, it's just the nth position. For example:
<pre>
INSERT INTO table VALUES(:11, :22, :22, :33);
</pre>
calling
<pre>
stmt->setString(3, "Apples");
</pre>
will replace the second ':22', right? It will become something like:
<pre>
INSERT INTO table VALUES(:11, :22, 'Apples', :33);
</pre>
About the summary: that would mean, that
<pre>
stmt->setSQL("BEGIN countFruit(:13, :666); END");
stmt->setString(1, "Apples");
stmt->setString(2, "Oranges");
</pre> is the correct way and it will be "translated" to:
<pre>
BEGIN countFruit( 'Apples', 'Oranges' ); END
</pre>
right?
One more case, sorry..
<pre>
stmt->setSQL("BEGIN countFruit(:1, :2, :3, :3, :2 ); END");
</pre>
How to set the second ':2' ? If ONLY "scanned left to right" is important and it stops on match (does not scan ALL parameters), does this mean, that to set the second ':2', I should use
<pre>
stmt->setString(4, "Apples");
</pre>
? Or it scans all placeholders and replaces the repeatable ones? In that case, I'll have to use
<pre>
stmt->setString(2, "Apples");
</pre>
to replace both ':2' ?
Edited by: Kiril Kirov on Jan 24, 2012 3:36 PM

Similar Messages

  • Prepared Statement with ORDER BY

    I am trying to use order by with prepared statement but it is not ordering.
    String sql = "SELECT * FROM MATERIAL WHERE (LOWER(NAMEE) LIKE ('%' || ? || '%') ORDER BY ? ";
    PreparedStatement ps=CM.getStatement(sql);
    ps.setString(1,p);
    ps.setString(2,sort);
              ResultSet r = ps.executeQuery();
    Can any one tell me how do I use prepared statement with order by

    You can not parameterize column names and such, only literals. You should build the ORDER BY clause dynamically.

  • HT4528 Why is it that everything is fine with my verizon account and apple is messing with my pre order of the iphone 5?

    Why is it that everything is fine with my verizon account and apple is messing with my pre order of the iphone 5 telling me that verizon is "rejecting" my order.. My verizon account is fine, and I am eligible for an upgrade, there is no past due balance.. the order went from being prepared to ship back to processing 2 days before it's supposed to get here.. still says it's going to deliver 9/21, yet it still stuck in processing mode, called apple for the past couple of days since i ordered it ON TIME and basically spoke to 17 different people telling me all different things and seems as if it just becomes more and more of a problem..

    this what most people say, track in on UPS website using your phone number. its TRUE and better tracking info
    more info here
    https://discussions.apple.com/thread/4311254?tstart=0

  • Why is it that everything is fine with my verizon account and apple is messing with my pre order of the iphone 5?

    Why is it that everything is fine with my verizon account and apple is messing with my pre order of the iphone 5 telling me that verizon is "rejecting" my order.. My verizon account is fine, and I am eligible for an upgrade, there is no past due balance.. the order went from being prepared to ship back to processing 2 days before it's supposed to get here.. still says it's going to deliver 9/21, yet it still stuck in processing mode, called apple for the past couple of days since i ordered it ON TIME and basically spoke to 17 different people telling me all different things and seems as if it just becomes more and more of a problem..

    this what most people say, track in on UPS website using your phone number. its TRUE and better tracking info
    more info here
    https://discussions.apple.com/thread/4311254?tstart=0

  • With iTunes match, order of the songs in my playlist of mobile devices is not the same as on my computer

    In my iTunes on computer, I have several smart play lists. Within each playlist, songs are set to a certain order. Some playlist songs order are organized by name, some playlists are organized by Album, some playlists are organized by artist etc.
    When I was syncing my iPhone and iPad directly with my computer, the playlists on my mobile device had same order of songs as on my itunes in computer.
    Now, I signed up for iTunes match. With iCloud sync, order of the songs in my playlist of mobile devices is not the same as on my computer. In fact, order of songs within a playlist appears to be completely random. Moreover, order of songs are different in my iPhone 4s and iPad 2
    How can I change the order of songs on my mobile devices or how do I make iTunes match to sync my songs such that within a playlist, my songs are in the same order as that of iTunes on my computer.

    Thanks mracole. I assume this means order of songs will work with regular play lists I iTunes match. Will try it this afternoon and report.
    Please let me know if my understanding is not correct.
    Best regards and thanks once again.

  • Problem with the order of the columns of a ALV

    I have a problem with a ALV, variants we keep this ALV does not record the order of the columns
    Thank you

    I suppose you want to change the sequence of columns of a ALV. If you can change it by clicking 'settings' of right-top corner of ALV. After done you can save the new settings into a new. If you find some abnormal behaviour, please check the settings by WDA component "wd_analyze_config_user".
    FYI.
    [http://help.sap.com/saphelp_nw70/helpdata/en/32/f26f73d81e11d1a26f0000e8a5a614/frameset.htm]

  • PLAYLIST PROBLEM: I did a playlist and after synchonising with my ipod, the order of the songs changed both in itunes and in the ipod. In itunes the order came alphabetically and in ipod randomly. I wanted that playlist for a party. HELP! THX

    PLAYLIST PROBLEM: I did a playlist and after synchonising with my ipod, the order of the songs changed both in itunes and in the ipod. In itunes the order came alphabetically and in ipod randomly. I wanted that playlistto be played in the order I made it for a party.
    Now I don't know what to do.
    Thank you very much

    Plug your iPod in and when it appears in iTunes, click on it from under Devices in the left hand pane.  This brings you to the Summary tab.  Locate and click on the Music tab.  What configurations do you have made from under this tab?  Is your iPod configured to sync those playlists?
    B-rock

  • How to change the order of the icons in the dock with Lion?

    Hello
    since I've installed Lion on my Mac I cannot change the order of the icons used for quick launch.
    Any idea how I customize the order of the icons?
    Thanks
    Mac-Fanatic

    I suspect you'd get a very prompt reply in the Lion forum:
    https://discussions.apple.com/community/mac_os/mac_os_x_v10.7_lion

  • Could not find prepared statement with handle 13

    Hi,
    I'm having a terrible problem: When I try to execute a SQL Query the following exception is thrown:
    * "java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Could not find prepared statement with handle 13."
    This exception is thrown is this line:
    boolean returnResultSet = ((PreparedStatement)sqlStatement).execute();
    The sqlStatement object is a java.sql.PreparedStatement that was received as a Statement in the method definition.
    The following query is being executed in this PreparedStatement:
    SELECT id_promocao, ds_nome, id_tipo, ds_sinopse, dt_lancamento, pt_site, pt_caminho_relativo, fl_ativo FROM TAB_CINE_GM ORDER BY ds_nome
    I'm using Macromedia JRun 4 build 61650 and I'm using MS-SQL Server 2000 as a database server.
    If anyone can help, I'll thanks a lot.
    Helcio Chaves
    S�o Paulo - SP - Brazil
    [email protected]

    There is a common way to check runtime type:
    if (sqlStatement instanceof PreparedStatement)
    returnResultSet = ((PreparedStatement)sqlStatement).execute();
    else
    returnResultSet = sqlStatement.execute();
    }By the way - I can't understand why you're trying to cast sqlStatement to PreparedStatement? It doesn't matter at all due to so-called polymorphism of all Java methods (except static ones). Anyway execute() will run for PreparedStatement but bot for Statement
    Enjoy,
    Pavel

  • What is the order of Column Names in Sqlite query results?

    I am writing an application using Adobe Air, Sqlite, and Javascript.
    After writing the following select statement:
              SELECT field1, field 2, field 3, field 4 FROM TableA;
    I would like to get the columnName/data combination from each row -- which I do successfully with a loop:
              var columnName="";
              for (columnName in selResults.data[i]) {
                   output+=columnName + ":" + selResultsdata[i][columnName] + ";";
    My issue is that the column names come out in a different order every time I run the query and never once have they come out in the desired order -- field 1, field 2, field 3, field 4.  If I run the query in Firefox's Sqlite Manager, the columns come out in the "proper" order. When I run them in Adobe Air, the order will be the same if I run the query mulitple times without closing the app.  If I make a change such as declaring the columnName variable with "" before the for column, or declare it as (var = columnName in selResults.data) , then the order changes.  If I shut down my app and re-open after lunch and run query, it comes out in another order.  At this time, I'm not interested in the order of the rows, just the order of the columns in each output row.  I've even tried assiging an index to columnName which seems to just pick up a single letter of the columnName.
    I'm in the process of changing my HTML presentation of the data to assign a precise columnName to an HTML table title, but I'm reluctant to let go of the above concept as I think my separation of HTML/presentation and Javascript would be better if I could use the solution described above.
    So, does anybody know how to force the order of the columnNames in my output -- or what I'm doing to cause it to come out in a different order?
    Jeane

    Technically there isn't any "order" for the return columns. They aren't returned as an Array -- they're just properties on an Object instance (a "generic object"). The random order you're seeing is the behavior of the for..in loop iterating over the properties of the object. Unfortunately, with a for..in loop there is no guaranteed order for iterating over properties (and, as you've seen, it tends to vary wildly).
    The only solution is to create your own list of the column names and sort it the way you want to, then use that to create your output. For example, use the for..in loop to loop over the properties, but rather than actually get the values, just dump the column names into an Array:
    var columnName="";
    var columns = [];
    for (columnName in selResults.data[i]) {
        columns.push(columnName);
    columns = columns.sort(); // just uses the default alphabetical sort -- you would customize this if desired
    var j = 0;
    for (j = 0; j < columns.length; j++) {
        columnName = columns[j];
        output+=columnName + ":" + selResultsdata[i][columnName] + ";";

  • Could not find prepared statement with handle %.

    Greetings. I've seen several posts for this error on the web, but no clear cut answers. I captured the code below in profiler, with the intention of replaying in mgmt studio.
    However, the attempt end in the following error: "Could not find prepared statement with handle 612."
    declare @p1 int
    set @p1=612
    declare @p2 int
    set @p2=0
    declare @p7 int
    set @p7=0
    exec sp_cursorprepexec @p1 output,@p2 output,N'@P0 int,@P1 int,@P2 int,@P3 int,@P4 bit',N'EXEC dbo.mySproc @P0,@P1,@P2,@P3,@P4 ',4112,8193,@p7 output,219717,95,NULL,1,0
    select @p1, @p2, @p7
    Something noteworthy is that my sproc only has 5 input parameters, but this makes it look like it has many more.
    How do I manipulate the code enough to make it work in mgmt studio? Thanks!
    TIA, ChrisRDBA

    In profiler you would normally see RPC:Starting and RPC:Completed. The statement shown in RPC staring is what you need to pick because as Erland explained, completed would show "funky" behavior.
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • For all entries changes the order of the itab

    Hi Experts
                 In the following query i have used two internal tables namely it_first and it_zlist.
                The material inwhich the it_zlist is different sorting order
          After executing this query, the order of the material inwhich the it_first is different from the it_zlist.
                 What could be the reason, pls explain me on this.
    select matnr test zsno ztnam from zmaster1
                into corresponding fields of table it_first
                      for all entries in it_zlist
                      where matnr = it_zlist-matnr.
    Thanks in advance.
    Regards
    Rajaram

    for all entries u should specified all primary key.
    sort by u condition.
    Effect
    If the addition FOR ALL ENTRIES is specified before the language element WHERE, then the components comp of the internal table itab can be used as operands when comparing with relational operators.
    The internal table itab must have a structured line type and the component comp must be compatible with the column col.
    The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher). In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY.
    The whole logical expression sql_cond is evaluated for each individual line of the internal table itab. The resulting set of the SELECT statement is the union of the resulting sets from the individual evaluations. Duplicate lines are automatically removed from the resulting set. If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.
    Notes
    In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO.
    The addition FOR ALL ENTRIES is only possible before WHERE conditions of the SELECT statement.
    If the additions PACKAGE SIZE or UP TO n ROWS are specified together with FOR ALL ENTRIES, they are not passed to the database system but are applied instead to the resulting set once all selected rows on the application server have been imported.
    With duplicated rows in the resulting set, the addition FOR ALL ENTRIES has the same effect as if addition DISTINCT were specified in the definition of the selection quantity. Unlike DISTINCT, the rows are not deleted from the database system but are deleted on the application server from the resulting set.
    Addition FOR ALL ENTRIES is only possible for WHERE conditions of the SELECT statement.
    Example
    Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.

  • In-list: does oracle follow the order of the items in the in-list?

    We have a partition table, each partition has one day's data. And we are using 4 partitions, every day the oldest partition will be truncated so that it could be reused next day. Some data will be sit in more than 1 partitions, and we need to get the newest data. The current partition has a partition_key=MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') + 1, 4).
    If oracle obeys the order of the items in the in-list, then the following sql should work and has the least cost. But I am not sure whether oracle run time engine will obey the order. I recalled Lewis had said run time engine might not follow the plan in the execution plan (explain plan).
    select *
      from tab
    where id=:id and partition_key in
           (MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') + 1, 4),
            MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') , 4),
            MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') -1, 4),
            MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY')-2, 4)) and rownum=1;If oracle doesn't follow the order in the in-list, does oracle follow the order of subquery in "union all", such as
    select * from
           select * from tab where where id=:id and partition_key =MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') + 1, 4)
              union all
           select * from tab where where id=:id and partition_key =MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') , 4)
              union all
           select * from tab where where id=:id and partition_key =MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') - 1, 4)
              union all
           select * from tab where where id=:id and partition_key =MOD(TRUNC(SYSDATE) - TO_DATE('01-JAN-2005', 'DD-MON-YYYY') - 2, 4)
    where rownum=1

    Is there an Oracle version number on your database?
    Is "Lewis" Jonathan Lewis? If so please post a link to his comment so we can read it and understand what you are referring to.
    If your table is indeed partitioned then please post the DDL that created it ... not every column but at least the partition key
    and the partioning template.
    Please also post your explain plan report generated from your DML statements by dbms_xplan.display.
    We can not help with what we can not see.

  • FindByPrimaryKey: Could not find prepared statement with handle 3

    I've inherited a WL61 application and been asked to make it work under WL81. We're using SQL Server 2000. We only access two tables. The XML got auto-converted during the upgrade, but I had to correct the RDBMS column names in the weblogic-cmp-jar.xml
    The application mostly works except the findByPrimaryKey fails with:
    ERROR ExecuteThread: '14' for queue: 'weblogic.kernel.Default' Administrator : TargetSessionBean - Error finding promotion with ID <2>
    javax.ejb.FinderException: Problem in findByPrimaryKey while preparing or executing statement: 'weblogic.jdbc.wrapper.PreparedStatement_weblogic_jdbc_base_BasePreparedStatement@95':
    java.sql.SQLException: [BEA][SQLServer JDBC Driver][SQLServer]Could not find prepared statement with handle 3.
    java.sql.SQLException: [BEA][SQLServer JDBC Driver][SQLServer]Could not find prepared statement with handle 3.
    at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
    at weblogic.jdbc.base.BaseExceptions.getException(Unknown Source)
    I've checked the database table and the row exisits with the appropriate PK (in this case a promotion with ID <2>).
    In the WL61 version the findByPrimaryKey was explicitly defined in the weblogic-cmp-rdbms-jar.xml as follows:
    <finder>
    <method-name>findByPrimaryKey</method-name>
    <method-params>
    <method-param>com.fujitsu.ftxs.corema.server.PromotionPK</method-param>
    </method-params>
    <finder-query><![CDATA[ (= $0 promotionId) ]]></finder-query>
    <finder-expression>
    <expression-number>0</expression-number>
    <expression-text><![CDATA[@0.promotionId]]></expression-text>
    <expression-type>int</expression-type>
    </finder-expression>
    </finder
    But I understand that with WL81 I should no longer define this - it's done implicitly - so I've removed this finder definition.
    Any help appreciated. Thanks,
    - Andy Abel

    I fixed it by switching from the using the BEA driver:-
    DriverName="weblogic.jdbc.sqlserver.SQLServerDriver"
    URL="jdbc:bea:sqlserver://host:1433"
    And using the Microsoft Driver instead:-
    DriverName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
    url=jdbc:microsoft:sqlserver://host:1433
    If anyone can explain why the Microsoft Driver works and the BEA driver does not I'd like to know.
    Thanks,
    - Andy Abel

  • Could not find prepared statement with handle 1.

    [Macromedia][SQLServer JDBC Driver][SQLServer]Could not find prepared statement with handle 1.
    I'm getting this error message in what appear to be random ways. The first time I look at a page I might not get it, but the second time I might. I discovered that removing a cfqueryparam tag worked, but that is not really a safe solution. I checked that the cf_sql_type matched the database field, and in one case changed a cf_sql_varchar to a cf_sql_char so it would match a SQL Server nchar(10) field. But still these errors. Any ideas? I've not had any luck Googling this.
    I should add that I'm running Coldfusion 9 as a Tomcat webapp on a Linux server. The database is SQL Server 2005, I think.

    Here's the one that is breaking now:
    <cfquery name="CheckCredentials" datasource="#application.crossreg_dsn#">
                                            SELECT [name_first]+' '+[name_last] as name
                                                        ,p.[uni]
                                                        ,p.email
                                                        ,p.role_id
                                                         ,r.role_name
                                                      ,p.external_program_id
                                              FROM [CrossReg].[dbo].[People] p
                                               INNER JOIN dbo.Roles r on r.role_id = p.role_id
                                              WHERE uni = <cfqueryparam cfsqltype="cf_sql_char" value="#Session.username#">
    </cfquery>
    Session.username is being returned from a CAS authentication system. I've never had troubles with it before.

Maybe you are looking for

  • How can I create an infinitely refilling draggable item in Cocoa-Applescript, Xcode?

    It's hard to explain. The only example I can give it how you can infinately drag buttons from Xcode Editor into a window, except instead of a button, I need a custom view, and instead of a window, I need a verticle list. How can I do this using Apple

  • Podcasts not Deleting

    Does anyone know the rules for how an iPod Classic determines that a Podcast has been listened to and should be deleted from the iPod on synch with iTunes? I have a number of Podcasts that are marked as listened, but are still on my iPod. (I only kee

  • Need help in design scenario

    Hi experts, I have a scenario in which XI put an xml file in a destination server (very simple scenario, SAP>Proxy>File receiver CC). The new request is: to make a call to SAP after having put file in destination. In this call I have to write to SAP

  • LGWR: Archivelog for thread 1 sequence 219 will NOT be compressed

    db-version 10.2.0.2 os windows server 2003 part of the alert log: Thread 1 cannot allocate new log, sequence 219 Private strand flush not complete Current log# 2 seq# 218 mem# 0: D:\ORACLE\PRODUCT\10.2.0\ORADATA\HTMLDB63\REDO02A.LOG Current log# 2 se

  • ITunes match option not showing in iPad2. Running iOS 5.1

    iTunes match option is not showing in my iPad 2 neither in my iPhone 4S under Music settings but works ok in my iMac and MacMini. Is there any setting to enable it in iOS? All devices are connected to the same apple ID