JDBC: Prepared statements with more parameters than column names

I'm using the latest version of the JDBC driver - 4.1.5605.100_enu - on Java 1.7, Linux.
I'm connecting to MS SQL Server 2012 Express Edition using a connection URL of the form jdbc:sqlserver://10.0.0.2;user=username;password=pwd;database=testdb1
I have a table with two columns. One is an ID (type bigint) and one is numeric(38, 19).
The following code works exactly as expected:
PreparedStatement stm = connection.prepareStatement("INSERT INTO myTable(id, num) VALUES (?, ?)")
// repeatedly set parameters using setLong, setBigDecimal, then addBatch
stm.executeBatch()
The following code does not work as expected:
PreparedStatement stm = connection.prepareStatement("INSERT INTO myTable(id, num) VALUES (?, ?),  (?, ?)");
stm.setLong(1, 1);
stm.setBigDecimal(2, new BigDecimal("1.234"));
stm.setLong(3, 2);
stm.setBigDecimal(4, new BigDecimal("1.234"));
stm.addBatch();
stm.executeBatch();
The code runs normally in the second case, but the second row inserted contains the wrong value in the "num" column - it's been rounded to 1.0 instead of stored as 1.234.
I think this may be because the driver does not understand the types of parameters whose indexes are beyond the number of columns in the insert statement. Running the following code on the second prepared statement:
System.err.println(stm.getParameterMetaData().getParameterTypeName(2)); // prints "numeric"
System.err.println(stm.getParameterMetaData().getParameterTypeName(4)); // fails with IndexOutOfBoundsException
As far as I can tell from the JDBC JavaDoc, this usage is valid and ought to work. Certainly it works as expected (including the parameter metadata) using PostgreSQL and their JDBC driver. Is this a bug in Microsoft's driver?

Hi dtn-cfl,
Thanks for your waiting.
Based on my research(using
SQL Server Profiler to trace DB events), the preparedStatement finally passes the below statements to SQL Server.
stm.setLong(1, 1);
stm.setBigDecimal(2, new BigDecimal("1.234"));
stm.setLong(3, 2);
stm.setNull(4, Types.DECIMAL);
declare @p1 int
set @p1=0
exec sp_prepexec @p1 output,N'@P0 bigint,@P1 decimal(38,3),@P2 bigint,@P3 decimal(38,0)',N'INSERT INTO myTable(id, num) VALUES (@P0, @P1), (@P2, @P3) ',1,1.234,2,NULL
select @p1
Pay attention to the @P3 decimal(38,0),  it seems(I don't have access to JDBC source code so that I have to use seem) that the
stm.setNull(4, Types.DECIMAL) will finally parsed as a type decimal(38,0). In SQL Server, to a
decimal datatype,one with smaller scale has a higher precedence. To understand the precedence, please see below code. If you have more interest in data type precedence, you can click
here.
declare @num1 decimal(38,3) --scale 3
declare @num2 decimal(38,2) --scale 2
set @num1 = 3.225
set @num2 = 3.22
select @num1 as num
union all
select @num2
output
num
3.23
3.22
@num1 get rounded to keep the column data type consistency, namely keep the column as type decimal(38,2)
Let's go back to your code, if you would like to make your code work properly, please see below.
stm.setLong(1, 1);
stm.setBigDecimal(2, new BigDecimal("1.234"));
stm.setLong(3, 2);
stm.setNull(4, Types.INTEGER);As per the above data type precedence link, a decimal has a higher precedence than integer, so your decimal will not get rounded.
Not only the case in your post, but also any data type inconsistency will lead to the rounding problem. See below.
stm.setLong(1, 1);
stm.setBigDecimal(2, new BigDecimal("1.234"));
stm.setLong(3, 2);
stm.setBigDecimal(4, new BigDecimal("1.2")); // or new BigDecimal("1.23") and any other decimal with different scale leads to rounding problem.
So when you set parameters for a prepareStatement like "INSERT INTO myTable(id, num) VALUES (?, ?),  (?, ?)" with more than one row, you should pay attention to data type consistency fact.
The Microsoft JDBC driver for SQL Server may not be that intelligent, however we can't say that is a bug definitely.
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support

Similar Messages

  • How to use INSERT INTO ALL statement in jdbc prepared statement with beans

    Kindly give me some example that how we can use "INSERT INTO ALL STATEMENT" in jdbc prepared statement inside a jsf bean?
    Actually i want to take employee id's of present employees using single jsf page and using one textbox for each employee id.
    How can i use INSERT INTO ALL statement to achieve this?
    Following is my code snippet.
    AttendanceBean.java:
    public class AttendanceBean {
    private int atteid;
    private String attdname;
    private int attday;
    private int attmonth;
    private int attyear;
    public static Connection getAttConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:globldb3";
    String username = "scott";
    String password = "tiger";
    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
    public String addAttendance(){
    Connection conn = null;
    PreparedStatement pstmt = null;
    boolean committed = false;
    try {
    conn = getAttConnection();
    conn.setAutoCommit(false);
    String query = "INSERT ALL INTO attendance VALUES (?,?,?,?,?)";
    pstmt = conn.prepareStatement(query);
    pstmt.setInt(1,this.atteid);
    pstmt.setString(2,this.attdname);
    pstmt.setInt(3,this.attday);
    pstmt.setInt(4,this.attmonth);
    pstmt.setInt(5,this.attyear);
    pstmt.executeUpdate();
    conn.commit();
    conn.setAutoCommit(true);
    committed = true;
    return "home.xhtml";
    } catch (Exception e) {
    e.printStackTrace();
    return "CRM.xhtml";
    } finally {
    try{
    if (!committed) conn.rollback();
    if (pstmt != null) pstmt.close();
    if (conn != null) conn.close();
    }catch(Exception e){
    e.printStackTrace();
    }

    Check this program for some info on Push buttons:
    1-DEMO_DYNPRO_PUSH_BUTTON
    2-DEMO_DYNPRO_MODULE
    3-DEMO_DYNPRO_ON_CONDITION
    Suppose Your screen is 101
    Then in that screen create one push button and assign it a function code.
    Now in the PAI of the 101 screen
    Create Module for user command
    Inside that module checc the sy-ucomm if sy-ucomm eq <Function code of your push button>
    Insert the values in database.
    *& Module USER_COMMAND_0101 INPUT
    process after input for screen 0101 *
    MODULE USER_COMMAND_0101 INPUT.
    CASE OK_CODE.
    WHEN 'SAVE'.
    *Insert the values here
    WHEN 'DISP'.
    ENDCASE.
    CLEAR OK_CODE.
    ENDMODULE. " USER_COMMAND_0101 INPUT
    Regards
    Neha
    Edited by: Neha Shukla on Dec 3, 2008 1:02 AM
    Edited by: Neha Shukla on Dec 3, 2008 1:02 AM
    Edited by: Neha Shukla on Dec 3, 2008 1:06 AM

  • 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

  • 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

  • Defining more parameters than a query needs

    Hi.
    When I run the following code, I get the error "ORA-01036: illegal variable name/number" .
    The problem is that I currently define more parameters than the query needs. Thats because I don't know how many bind variables the query uses, and I would not like to parse the query ...
    I don't understand why I have to define exactly the same number of parameters, and in the exact order ... It doesn't make sense. As bind variables have names, there should be no problem passing more parameters or parameters in a different order: the binding should be done by name...
    I'm currently using Oracle10g, ODP.NET and .NET Framework 2.0.
    I would appreciate any help ...
    Thank you.
    Ricardo Coimbras
    ===== BEGIN VB.NET CODE =====
    Sub Execute_Query(ByVal SqlString as String)
    Dim ObjCmd As OracleCommand
    Dim DataAdap As OracleDataAdapter
    Dim outDsCorpo As DataSet
    Dim Constroi_Conn_String_Oracle As String
    Dim mObjConnOracle As OracleConnection
    Constroi_Conn_String_Oracle = "User ID=uuu" & _
    ";Password=ppp" & _
    ";Data Source=bd" & _
    ";Pooling=false"
    mObjConnOracle = New OracleConnection(Constroi_Conn_String_Oracle)
    mObjConnOracle.Open()
    ObjCmd = mObjConnOracle.CreateCommand()
    ObjCmd.CommandType = CommandType.Text
    ObjCmd.CommandText = SqlString
    ObjCmd.Parameters.Add("p1", OracleDbType.Char, 3, "001", ParameterDirection.Input)
    ObjCmd.Parameters.Add("p2", OracleDbType.Char, 3, "001", ParameterDirection.Input)
    DataAdap = New OracleDataAdapter(ObjCmd)
    outDsCorpo = New DataSet()
    DataAdap.Fill(outDsCorpo)
    GridView1.DataSource = outDsCorpo
    GridView1.DataBind()
    DataAdap = Nothing
    ObjCmd = Nothing
    mObjConnOracle.Close()
    mObjConnOracle.Dispose()
    mObjConnOracle = Nothing
    End Sub
    Execute_Query "select * from map.t_mapa_def where mapa_def_cod = :p1 order by mapa_def_cod"
    ===== END VB.NET CODE =====

    Hi,
    BindByPosition is the default behavior as per the docs, and you can change that by setting cmd.BindByName=true which adds a little bit of extra overhead.
    That wont fix the error seen when binding a random number of parameters to the statement though. You need to bind the correct number and types of parameters.
    Greg

  • 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.

  • 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

  • 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.

  • 'Find an Item' search on list with more items than view limit

    Hello all
    The 'Find and Item' search on a list with more items than the view limit appears to filter results according to where you are in that list.  So if I search on the allitems page displaying items 1-100 I get hits from the entire list.  But if I arrow
    through to view items 201-300 and repeat the same search only items from 201 to the end of the list are returned
    I'm assuming this is not how it should work i.e. it should always return results from the whole list.  Is there a way to make that so (other than increasing the view limit to something huge so that all items are always displayed)
    Many Thanks
    Dan

    Hi,
    According to your post, my understanding is that Find an item Search box in List didn't returned any results.
    The problem is due to a difference between the Content Source defined for the crawl and the default zone defined in the Alternate Access mapping.
    You need to change the Alternate Access Mapping configuration.
    For more information, you can refer to:
    http://blog.jonathanroussel.com/2009/01/sharepoint-search-using-this-site-or.html
    http://blog.dafran.ca/post/2011/07/02/SharePoint-does-not-return-any-search-results.aspx
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Dynamic UPDATE statement with parameters for column names.

    Hello,
    On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
    On the other hand, in this Re: execute immediate with dynamic column name update and many other
    posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
    dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
    WHERE ST IN
    (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
    '||P_ST||' = CO.ST AND
    CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
    CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
    EXECUTE IMMEDIATE dynSQL ;
    Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
    The compiling works fine and I use Oracle 11g.
    http://psoug.org/definition/EXECUTE_IMMEDIATE.htm

    OK I extracted from all of your posts so far that I have to use "bind-variables with :"
    From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
    set serveroutput on format wraped;
    DECLARE
    dynSQL VARCHAR2(5000);
    P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
    P_ST                VARCHAR2 (100) :='32132';
    BEGIN
    dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
                  WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
                  '||:P_ST||'                           = CO.ST                  AND
                  CO.'||:P_ENT_E_G_NAME||'     > '||:P_ENT_E_G_WE||' AND
                  CO.'||:P_ENT_B_G_NAME||'    
    < '||:P_ENT_E_G_WE||')';
    --this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
    dbms_output.enable;
    dbms_output.put(dynSQL);
    --EXECUTE IMMEDIATE dynSQL;    
    END;Problem:I think I figured it out, the dates that I parse into the query need additional '

  • Prepared Statement with SQL 'IN' Clause

    Hi,
    I am trying to write a JDBC SQL call to a database using a prepared statement, the call looks something like:
    select *
    from table
    where field in (?, ? ,?)
    this thing is that i don't know how many 'IN' parameters are needed until runtime (they come from a List), so is there an easy way of dealing with this, I haven't been able to find any information on this problem anywhere?

    >
    Hmmm...more expensive than say doing a query on on 2 billion rows with no index?
    More expensive than doing a cross server join?
    More expensive than doing a restore?
    I knew that someone would point this out. :)
    I just tried to exaggerate the importance of cursor sharing. This is one of the most important topic in DBMS world, but quite often ignored by JAVA world. I hope that you understand my good intention.
    >
    2. Insert data corresponding to bind variable to "T". Interesting idea. Please provide the algorithm for that. The only ones I can come up with
    1. Involved creating a "dynamic" SQL for the insert
    2. Doing multiple cross network inserts.
    The first of course is exactly what you said your solution prevented. The second will be more expensive than sending a single dynamically created select.Hopefully, this is not just an "interesting" idea, but very common technique in DBMS. Actually one of the common techniques. There are couple of ways to handle this kind(variable number of bind variables in "IN" clause) of problem.
    What i commented was that the simplest one. It's like this:
    (based on Oracle)
    SQL> create global temporary table bind_temp(value int);
    PreparedStatement stmt = con.prepareStatement("INSERT INTO bid_temp VALUES(?)");
    for(...) {
         stmt.setInt(1, aValue)
         stmt.addBatch();
    stmt.executeBatch();
    Statement stmt2 = con.executeQuery("SELECT * FROM target_table WHERE id IN (bind_temp)");
    ...Doesn't it look pretty? Pretty for both Java developers and DBAs.
    By virtue of the mechanism of batch processing, the total DBMS call is just twice and you need just 2 completely sharable SQL statements.
    (Hopefully you might understand that Oracle global temporary table is just session scope and we don't need them to be stored permanently)
    Above pattern is quite beneficial than these pattern of queries.
    SELECT * FROM target_table WHERE id IN (?)
    SELECT * FROM target_table WHERE id IN (?,?)
    SELECT * FROM target_table WHERE id IN (?,?,?)
    SELECT * FROM target_table WHERE id IN (?,?,?,?,.......,?)
    If you have large quantity of above patterns of queries, you should note that there are another bunch of better techniques. I noted just one of them.
    Hope this clairfies my point.

  • Prepared statement takes much longer than statement..

    Hi community,
    At the moment I'm trying to migrate my j2ee application from DB2 to Oracle. I'm using database version 10.2.0.3 and driver version 10.2.0.4.
    After copying all data from DB2 to Oracle, I've started testing the application with the new database. During this process, a problem occurs when using prepared statements.
    For example, when I'm trying to execute the following sql statement:
    SELECT
    LINVIN.BBASE , INVINNUM , INVINNUMALT , LINVIN.LSUPPLIERNUM , LINVIN.COMPANYCODE , ACCOUNT , INVINTXT , INVINSTS , INVINTYP , INVINDAT , RECEIPTDAT , POSTED , POSTINGDATE , CHECKCOSTCENTER , WORKFLOWIDEXT , INVINREFERENCE , RESPONSIBLEPERS , INVINSUM , INVINSUMGROSS , VOUCHERNUM , HASPOSITIONS , LSUPPLIER.AADDRLINE1
    from LINVIN, LSUPPLIER
    where LINVIN.BBASE = LSUPPLIER.BBASE
    and LINVIN.LSUPPLIERNUM = LSUPPLIER.LSUPPLIERNUM
    and LINVIN.BBASE = ? and LINVIN.INVINNUM = ?
    order by LINVIN.BBASE, LINVIN.INVINDAT DESC
    The execution time, when using a simple java.sql.Statement, amounts to 100 millis. But if I execute the same statement with a java.sql.PreparedStatement it takes about 30.000 millis.
    I tried to do a explain plan on both types with the following results:
    With java.sql.Statement:
    PLAN_TABLE_OUTPUT
    Plan hash value: 1286706273
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 1 | 225 | 4 (0)| 00:00:01 |
    | 1 | NESTED LOOPS | | 1 | 225 | 4 (0)| 00:00:01 |
    | 2 | TABLE ACCESS BY INDEX ROWID| LINVIN | 1 | 136 | 3 (0)| 00:00:01 |
    |* 3 | INDEX UNIQUE SCAN | PK_2540516 | 1 | | 2 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    | 4 | TABLE ACCESS BY INDEX ROWID| LSUPPLIER | 16922 | 1470K| 1 (0)| 00:00:01 |
    |* 5 | INDEX UNIQUE SCAN | PK_177597 | 1 | | 0 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    3 - access("LINVIN"."BBASE"='PRAK' AND "LINVIN"."INVINNUM"='0010344820')
    5 - access("LSUPPLIER"."BBASE"='PRAK' AND
    "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
    With java.sql.PreparedStatement:
    PLAN_TABLE_OUTPUT
    Plan hash value: 957014775
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 37 | 8325 | | 5850 (1)| 00:01:11 |
    | 1 | MERGE JOIN | | 37 | 8325 | | 5850 (1)| 00:01:11 |
    |* 2 | TABLE ACCESS BY INDEX ROWID| LINVIN | 34 | 4624 | | 3442 (1)| 00:00:42 |
    |* 3 | INDEX FULL SCAN | LINVOICE_LSUPPLIER_FK | 3410 | | | 999 (2)| 00:00:12 |
    PLAN_TABLE_OUTPUT
    |* 4 | SORT JOIN | | 101K| 8824K| 19M| 2408 (1)| 00:00:29 |
    | 5 | INDEX FAST FULL SCAN | LSUPPLIERAL1 | 101K| 8824K| | 329 (1)| 00:00:04 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    2 - filter(SYS_OP_C2C("LINVIN"."INVINNUM")=:2)
    3 - filter(SYS_OP_C2C("LINVIN"."BBASE")=:1)
    4 - access("LINVIN"."BBASE"="LSUPPLIER"."BBASE" AND
    "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
    filter("LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM" AND
    "LINVIN"."BBASE"="LSUPPLIER"."BBASE")
    I checked the tables and the indexes and everything looks fine. I have an index over the where clause (PK), the order by clause and the join criterias. I also analyzed the tables and the indexes and also started a rebuild on them.
    Indexes table LINVIN:
    PK_2540516 --> index on LINVIN(BBASE, INVINNUM)
    LINVOICE_LSUPPLIER_FK --> index on LINVIN(BBASE, LSUPPLIERNUM)
    LINV_INVDAT --> index on LINVIN(BBASE, INVINDAT DESC)
    Indexes table LSUPPLIER:
    PK_177597 --> index on LSUPPLIER(BBASE, LSUPPLIERNUM)
    LSUPPLIERAL1 --> index on LSUPPLIER(BBASE,LSUPPLIERNUM,AADDRESSLINE1) [why is Oracle using this index, when addressline1 isn't in the statement?]
    Can somebody tell me please, why the prepared statement takes a completely different way than the normal statement and how can I get the prepared statement working like the other?
    I would really appreciated, if somebody can help me with this issue, because I'm really getting more and more distressed...
    Thanks in advance,
    Tobias

    With java.sql.Statement:
    Predicate Information (identified by operation id):
    > 3 - access("LINVIN"."BBASE"='PRAK' AND
    "LINVIN"."INVINNUM"='0010344820')> 5 - access("LSUPPLIER"."BBASE"='PRAK' AND
    >
    LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
    With java.sql.PreparedStatement:
    Predicate Information (identified by operation id):
    > 2 - filter(SYS_OP_C2C("LINVIN"."INVINNUM")=:2)
    3 - filter(SYS_OP_C2C("LINVIN"."BBASE")=:1)> 4 - access("LINVIN"."BBASE"="LSUPPLIER"."BBASE"
    AND
    LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
    ilter("LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNU
    M" AND
    "LINVIN"."BBASE"="LSUPPLIER"."BBASE")
    the tables and the indexes and everything looks fine.Notice the SYS_OP_C2C function Oracle is applying in your code with the prepared statement, it is doing this because the bind variable is not of the same data type as your column. So it's taking your column in the table, applying a function to convert it into the same data type as your bind variable (which destroys any possibility of using an index).
    If you ensure the prepared statement is binding type for type this should magically go away.

  • How to create a table with more tan 20 columns

    I created a A4 landscape document to make a calendar for the next year.
    To add the date information I need to insert a table with 32 columns (name of month + 31 days). It should be possible to create a table with a over all width of 29.7 cm (consisting of 1 column of 4.9 cm and 31 columns with 0.8 cm)?
    Remark: Yet reduced all indention's (? German: Einzug) and other spacers and the size of used font of the table.

    Hello Till,
    unfortunatly Pages connot create a table with more than 20 columns. This is no question of size or place.
    But you can create two tables, set the most right border of the fist table to "no line" and align the second table (with the other 12 columns) at the right side of the first table. Now you have "one" table with 32 columns.
    I have done this with my driving book (Fahrtenbuch, um es korrekt zu schreiben and it works fine.
    Frank.

  • Using once created prepared statement with different connections in Oracle

    Can I use same statement cash using different connections in Oracle
    For example I have a prepared statement p1. After its using i close connection (return it to the pool)
    Next time I want use p1 statement using another connection.
    Question : When I creat p1 in second time ,is it returned from cash or created as a new statement. And what I should do to use once prepared statement using differend connections.
    Thaks.

    As far as I know a PreparedStatement lives and dies with the Connection that created it. So, you cannot use a PreparedStatement with other Connection instances than the one that created it.
    You will have to recreate the PreparedStatement for each time you open a connection, or use the same PreparedStatement and NOT close the Connection in between. The last suggestion can be risky though, if you never close the connection...
    Jakob Jenkov
    www.jenkov.com

  • Prepared Statement with "INTERVAL ? DAY" clause

    Hi,
    I am having problems when using a INTERVAL ? DAY clause in a
    preparedStatement in Oracle 8i with the classes12.zip jdbc
    driver.
    The code following code:
    String sql1 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '10' DAY";
    String sql2 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '?' DAY";
    String sql3 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL ? DAY";
    try {
    st = con.prepareStatement(sql1);
    ResultSet rs = st.executeQuery();
    System.out.println("1 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql2);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("2 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql3);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("3 successful");
    catch (Exception e) {
    System.err.println(e);
    produces this output:
    1 successful
    java.sql.SQLException: ORA-01036: illegal variable name/number
    java.sql.SQLException: ORA-00933: SQL command not properly ended
    Can anybody help me figuring out what's wrong with the 2nd or
    3rd prepared statement?
    Thanks
    Bernie

    Hi,
    I am having problems when using a INTERVAL ? DAY clause in a
    preparedStatement in Oracle 8i with the classes12.zip jdbc
    driver.
    The code following code:
    String sql1 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '10' DAY";
    String sql2 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '?' DAY";
    String sql3 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL ? DAY";
    try {
    st = con.prepareStatement(sql1);
    ResultSet rs = st.executeQuery();
    System.out.println("1 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql2);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("2 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql3);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("3 successful");
    catch (Exception e) {
    System.err.println(e);
    produces this output:
    1 successful
    java.sql.SQLException: ORA-01036: illegal variable name/number
    java.sql.SQLException: ORA-00933: SQL command not properly ended
    Can anybody help me figuring out what's wrong with the 2nd or
    3rd prepared statement?
    Thanks
    Bernie

Maybe you are looking for

  • Problems running project in OPM 10.2 that was created in OPM 10.1

    Hi, I have a project created in OPM 10.1.0.27 and when I open it in OPM 10.2.0.110 I get the following message: "Your project is version 10.1.0.27 and needs to be upgraded to the latest version. A backup folder named 'Development 10.1.0.27-1' will be

  • E51 update and memory card password problem

    This morning I updated the software of my e51. But after update, it asks me password of my memory card and I entered all the possible passwords but it doesn't accept.  What can I do about it? I searched internet tried some ways to unlock but they jus

  • Creating a movie in widescreen format.

    Hello, I have a question, I'm hoping that someone can help me out. I have created a movie in iMovie, what I need is to create a file that I can transfer over to my PC and then play it on the PC. When I have done this, I have created a AVI file (4 min

  • Fiori LaunchPad : Images on Application tile

    Hello All, In Launchpad designer , We can add Icons for the application tile. Is it possible to add IMAGE rather than ICON here? does the new LaunchPad designer supports this feature ? Regards, Sheetal Tags edited by: Michael Appleby

  • Has anyone fixed wireless printing to HP LaserJet 1015 via AEBS Snow

    Dear All I've searched the forums, read numerous posts by HP Mac Architect (thanks BTW for your amazing efforts), tried various things, and still can't get wireless printing back on my HP LaserJet 1015. My set up is: Intel Core Duo 20" iMac, 10.6.1,