Statement.RETURN_GENERATED_KEYS in PreparedStatement

Hi everyone,
I need to insert a new record to a table in Mysql DB (using JDBC driver). After inserting is successful, I want to get the new ID number (it is a Primary key). Now I have problem using 'Statement.RETURN_GENERATED_KEYS' in PreparedStatement.
Here is the code:
    public void create(Item item)
    throws SQLException, InvalidFieldException {
          String creatSql = "INSERT INTO sc_item (catID, itemName, inStock, itemDesc, "+
              "imageName, salePrice, lastUpdateDate  ) values (?, ?, ?, ?, ?, ?, NOW())";
        PreparedStatement insert = conn.prepareStatement(creatSql,
            Statement.RETURN_GENERATED_KEYS);
        try {
            populateAdd(insert, item);
            insert.executeUpdate();
            ResultSet key = insert.getGeneratedKeys();
            if (!key.next()) {
                throw new RuntimeException(
                    "Can't retrieve generated primary key!");
            item.setItemId(key.getLong(1));
            key.close();
        } catch (SQLException e) {
            if (InvalidFieldException.SQL_STATE.equals(e.getSQLState())) {
                throw new InvalidFieldException(e);
            } else {
                throw e;
        } finally {
            insert.close();
    private void populateAdd(PreparedStatement stmt, Item item)
    throws SQLException {
        stmt.setInt(1, 1);
        stmt.setString(2, item.getItemName());
        stmt.setInt(3, item.getInStockNum());
        stmt.setString(4, item.getItemDesc());
        stmt.setString(5, item.getItemImgName());
        stmt.setDouble(6, item.getSalePrice());
    }in this line:
PreparedStatement insert = conn.prepareStatement(creatSql,
Statement.RETURN_GENERATED_KEYS);
If I don't use 'Statement.RETURN_GENERATED_KEYS', inserting is successful, no problem at all (I have tested it, also I use similar statement in the code of table update).
Does anyone know what causes the problem?
(I have 'mysql-connector-java-3.1.10-bin.jar' in /WEB-INF/classes/lib folder, my project runs on Tomcat 5.5)
Thanks in advance

This seems to be a bug in the mysql driver. Here is a link to the bug (#13668):
http://bugs.mysql.com/bug.php?id=13668

Similar Messages

  • How to get the real SQL statement from a preparedstatement?

    Hi,
    I am trying to log the actual SQL sent to database by the preparedStatement. Since the original SQL I used to prepare the statement has a lot of "?" in it, after setting all the parameters in the preparedStatement, I want to get the final SQL statement executed. Is there a way to get it? Probably the SQL will depend on different drivers.
    Thanks in advance.

    Thanks, changhsu. I tried the tracing technique. But it only prints out the original SQL statement sent to the preparedStatement. The following is part of the log file:
    ======================================================================
    --------NetDirect JSQLConnect Version:2.2708--------
    2002-04-10 14:23:54.818 (1) Connection attempt number 1 Connection ID:1 for host:perseus
    2002-04-10 14:23:55.429 (1) JSQLConnect(2.2708) Trial license - expires on:Thu Apr 25 17:47:32 CDT 2002, unlimited connections
    2002-04-10 14:23:55.449 (2) Connection allocated from pool ID:2
    2002-04-10 14:23:55.72 (2) [Thread[Thread-6,5,main], IO:88cb4, Dbc:1346]] SELECT SHARED_DRIVES FROM EPM_PREFS WHERE PRODUCT='PE'
    2002-04-10 14:23:57.913 (2) Connection closed and returned to connection pool ID:2
    2002-04-10 14:23:58.193 (3) Connection attempt number 2 Connection ID:3 for host:perseus database:epm20 SQL6.5:false
    2002-04-10 14:23:58.203 (3) [Thread[Thread-6,5,main], IO:88cb3, Dbc:1347]] use epm20 set quoted_identifier,ansi_null_dflt_on,ansi_padding on set textsize 2147483647 set transaction isolation level read committed set implicit_transactions off
    2002-04-10 14:24:00.356 (4) Connection allocated from pool ID:4
    2002-04-10 14:24:01.168 (4) [Not Loged In@localhost, IO:88cb2, Dbc:1347]] PreparedStatement::prepare stmt:SELECT PASSWD FROM RESOURCE_INFO WHERE USER_ID=? AND DELETE_FLG IS NULL
    2002-04-10 14:24:01.448 (4) [Not Loged In@localhost, IO:88cb2, Dbc:1347]] RPC:sp_prepare
    2002-04-10 14:24:01.488 (4) [Not Loged In@localhost, IO:88cb2, Dbc:1347]] RPC:sp_execute
    =======================================================================
    I did not try to trace in SQL Server 7. I will have to find out how to do that first.
    Thanks again.

  • Urgent help Statement v/s PreparedStatement

    iam using Statement object but java specification says, PreparedStatement makes more efficient compared to Statement object can any body explain briefly about it.

    i know that dynamically u can give values but specification says
    PreparedStatements make the description calls at construction time,
    Statements make them on every execution.what this means If you want to execute a sql statement multiple times, then a prepared statement is more efficient.
    eg
    Statement stmt = connection.createStatement();
    stmt.execute("insert into users (username) values ('Tom')");
    stmt.execute("insert into users (username) values ('Dick')");
    stmt.execute("insert into users (username) values ('Harry')");vs
    [code
    String sql = "]insert into users (username) values (?);";
    stmt = connection.prepareStatement(sql);
    stmt.setString(1, "Tom");
    stmt.execute();
    stmt.setString(1, "Dick");
    stmt.execute();
    stmt.setString(1, "Harry");
    stmt.execute();
    With the first one, the database has to parse the query each time, check it for syntax errors, and then execute it.
    Using a prepared statement, the parsing/error checking only happens once - when you prepare it. After that you can call the same statement with different values, and it will use that already "parsed and prepared" statement.
    It already knows exactly the column types that will be returned from the query - that bit can't change. With a Statement, it has to work from scratch each time.
    If you are executing the same piece of SQL hundreds/thousands of times, only changing the values, then Prepared statements come into their own.
    Cheers,
    evnafets

  • CF 8 and  prepared statement RETURN_GENERATED_KEYS

    It seems that for CF 8 is using RETURN_GENERATED_KEYS when
    creating prepared statements. Is there any way to change this
    behavior?

    It seems that for CF 8 is using RETURN_GENERATED_KEYS when
    creating prepared statements. Is there any way to change this
    behavior?

  • Statement vs PreparedStatement

    Can anyone offer guidelines ( or point me to documentation) which describes when/why use a
    Statement as opposed to a PreparedStatement.
    I realize that a PreparedStatement can be defined with Bind variables for later substitution and thus the statement gets compiled only once thereby being more efficient.
    But is that the only difference ? does it make sense to use a PreparedStatement even if there are no Bind variables ?

    Whenever you want to re-use a statement you should use Statement and not PreparedStatement.
    Statements can effectively only be used once, since you provide the SQL text to the execute method: this means that when issuing execute (or executeQuery) the statement is always fully reparsed by the database.
    If you have a PreparedStatement object, you can re-execute it, and the database will reuse the parsed statement.

  • Statement or preparedStatement

    Hi all guys,
    Please tell me when we use Statement and when preparedStatement?
    As many times we use preparedStatement so what is the use of Statement ?
    And what is the advantage of using preparedStatement ? What is difference between in both ?
    please reply !!!!!!!!!
    amitindia
    India

    I was hoping you would ask that ;-)
    Suppose your web application asks the user for their ID number. They type it into a box and click submit. This ends up calling the following method:
    public List processUserID(String idNumber)
       throws SQLException
       String query = "SELECT role FROM roles WHERE id = '" + idNumber + "'";
       ResultSet rs = this.connection.executeQuery(query);
       // ... process results ...
    }If out of a sense of informed malice, your user enters the following text into the ID number field:
    12345'; TRUNCATE role; SELECT 'They may be able to drop the contents of your role table, because the string that ends up in "query" will be:
    SELECT role FROM roles WHERE id = '12345'; TRUNCATE role; SELECT ''They have successfully injected SQL into your application that wasn't there before, hence the name. The specifics of this depend to some extent on your database, but there's some pretty portable SQL you can use to achieve this.
    On the other hand, if you use a prepared statement:
    public List processUserID(String idNumber)
       throws SQLException
       String query = "SELECT role FROM roles WHERE id = ?";
       PreparedStatement statement = this.connection.prepare(query);
       statement.setString(id,idNumber);
       ResultSet rs = this.connection.executeQuery(query);
       // ... process results ...
    }The database is told to compile the SQL in query first. The parameter is then submitted - so whatever you put into it will never get executed as SQL (well, ok, it's possible if you're passing it as a parameter to a stored proc, but it's very unlikely) - it will just return no matching records (because there won't be any users with id "12345'; TRUNCATE role; SELECT '"
    Hope that clarifies.
    Dave.

  • Problems with PreparedStatement when select restrict are byte params

    Hi,
    i have a problem trying to select information when the "select" has a byte restrict.
    The table in database is:
    CREATE TABLE `positions` (
    `PKID` int(10) unsigned NOT NULL auto_increment,
    `POSCODE` varbinary(30) NOT NULL,
    `ISWTURN` binary(1) NOT NULL,
    `QTT_GAMES` int(10) unsigned NOT NULL default '1',
    PRIMARY KEY (`PKID`),
    UNIQUE KEY `UNIQ_POS` (`POSCODE`,`ISWTURN`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    And the test code to get the qtt_games is :
    conn = DriverManager.getConnection (url,user,pwd);
    byte bcode[] = poscode.getByteArrayCode();
    // bcode is inserted ok in another preparedstatement...
    String query = "SELECT qtt_games FROM positions "+
    "WHERE poscode=? and iswturn=?";
    PreparedStatement pstmt = conn.prepareStatement(query);
    pstmt.setBytes (1,bcode);
    pstmt.setByte (2,poscode.getIsWhiteTurn()); //it returns a byte
    ResultSet rs = pstmt.executeQuery (query);
    When pstmt.executeQuery is reached, it's thrown the exception:
    com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=? and iswturn=?' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3099)
    at com.mysql.jdbc.Statement.execute(Statement.java:695)
    at app.server.bbdd.MYSQLBDManager.getGamesBasicInfo(MYSQLBDManager.java:942)
    at app.server.bbdd.MYSQLBDManager.main(MYSQLBDManager.java:1068)
    Can anybody tell me what's wrong?? I think the query is ok, but don't know what's happening with this...
    Lots of thanks.

    Hi,
    sorry, i know i've post this same message by error in "new to java" thread.... (i'm new in the forum... can i delete the wrong comment??)
    The SQLState is 42000 (syntax error), but it doesn't give me much information because i had already searched in google why can be the cause of it, but there are only a few comments about problems like this, without a solution...
    The column poscode in the table positions contains an array of bytes that codify a position in a chess board. I've to use this in the WHERE clause because i'm developing a chess game consulting project where there are millions of different positions and i've to get the games that have the same position in it's position history.
    The code to insert the positions is:
    query = "INSERT INTO positions VALUES "+
         "(null,?,?,default) "+
         "ON DUPLICATE KEY UPDATE qtt_games=qtt_games+1";
    pstmt = conn.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
    pstmt.setBytes(1,bcode);
    pstmt.setByte(2,poscode.getIsWhiteTurn());
    pstmt.executeUpdate();
    which works ok and positions can be seen from mysql browser, but i can't select them using the PreparedStatement..
    I have been searching a lot of information about this problem with no results... this is the why i posted this...
    Any help will be useful, thanks.

  • Mysql PreparedStatement problem

    Hi
    I am having trouble updating a database with PreparedStatement. I am using two place holders one of theme which is a String (descr) fails to update.
    I am using
    Connector/J 3.1.13 with mysql 1.4
    here is my code
                        PreparedStatement pstmt = PrimaryConWrapper.getConnection().prepareStatement("INSERT INTO INVOICE_ENTRYES(i_id,descr,value,ts) VALUES("+id+",?,?,0)");
                        for(String eDescr:inve.keySet()){
                            pstmt.clearParameters();
                            int val = inve.get(eDescr);
                            pstmt.setString(1,eDescr);
                            pstmt.setInt(2,val);
                            int rts = pstmt.executeUpdate();
                            assert (rts==2):"In valid number of records updated "+rts;
                        }and I am getting an AssertionError
    Exception in thread "main" java.lang.AssertionError: In valid number of records updated 1
    and my daya base looks like this
    mysql> SELECT * FROM INVOICE_ENTRYES;
    +----+------+-------+------------+---------------------+
    | id | i_id | descr | value      | ts                  |
    +----+------+-------+------------+---------------------+
    | 33 |   13 |       |   50396417 | 0000-00-00 00:00:00 |
    | 34 |   13 |       | 1969358848 | 0000-00-00 00:00:00 |
    | 35 |   13 |       | 1750080256 | 0000-00-00 00:00:00 |
    | 36 |   13 |       | 1868762368 | 0000-00-00 00:00:00 |
    +----+------+-------+------------+---------------------+

    I cannot close the connection in my code because the connection is universal per login. How ever I tried you solution and I get this exception. I am not sure why this is but it could be because of the timestamp value.
                private int add(Invoice in)throws UnknownTypeException,DataSourceException,TypeMismatchException{
                    Connection con = null;
                    try{
                    if(checkName(in))throw new TypeMismatchException("Invoice "+in.getName()+" already exists");
                        String name = in.getName();
                        String descr = in.getDescr();
                        Date date = in.getDate();
                        //invlice entry map
                        Map<String,Integer> inve = in.getEntries();
                        int spId = in.getParent().getId();
                        int jobId = in.getJobMeta().getId();
                        Statement stmt = PrimaryConWrapper.getConnection().createStatement(
                                ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
                        stmt.executeUpdate("INSERT INTO INVOICES(dt,name,descr,sp_id,j_id,ts) VALUES('"+date+"','"+name+"','"+descr+"',"+spId+
                                ","+jobId+",0)",Statement.RETURN_GENERATED_KEYS);
                        ResultSet rs = stmt.getGeneratedKeys();
                        boolean chk = rs.next();
                        assert chk :"no keys returned";
                        int id = rs.getInt(1);
                        assert !rs.next():"morethan one key returned";
                        rs.close();
                        stmt.close();
                        con = PrimaryConWrapper.getConnection();
                        con.setAutoCommit(false);
                        PreparedStatement pstmt = PrimaryConWrapper.getConnection().prepareStatement("INSERT INTO INVOICE_ENTRYES(i_id,descr,value,ts) VALUES(?,?,?,?)");
                        for(String eDescr:inve.keySet()){
                            pstmt.clearParameters();
                            int val = inve.get(eDescr);
                            pstmt.setInt(1,id);
                            pstmt.setString(2,eDescr);
                            pstmt.setInt(3,val);
                            pstmt.setInt(4,0);
                            System.out.println(eDescr+","+val);
                            int rts = pstmt.executeUpdate();
                            assert (rts==1):"In valid number of records updated "+rts;
                        con.commit();
                        pstmt.close();
                        return id;
                    catch(SQLException sqle){
                        try{if(con!=null)con.rollback();}catch(Exception e){}
                        throw new DataSourceException("could not add Invoice",sqle);
                    finally{
                        try{if(con!=null)con.setAutoCommit(true);}catch(Exception e){}
                }and the exception is
    Caused by: java.sql.SQLException: Incorrect arguments to mysql_stmt_execute

  • JDBC PreparedStatement with Oracle 8.0.5 on Linux

    As the subject stated, I am using Oracle 8.0.5 on a Linux machine.
    When I am using a PreparedStatement, somehow, the binded variables are reversed in order.
    E.g.
    String sql = "INSERT INTO TABLE1 (X, Y) VALUES (?, ?)";
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setString(1, "1");
    ps.setString(2, "2");
    ps.executeUpdate();
    When I run the above, the insertion is successful. However, when I select the table, this is what I get.
    X Y
    2 1
    The values are reversed.
    This is the same for update statement too.
    If I do this,
    "UPDATE TABLE1 SET X = ? WHERE Y = ?"
    ps.setString (1, "3");
    ps.setString (2, "1");
    The above will not be successful.
    If I do this,
    ps.setString (2, "3");
    ps.setString (1, "1");
    The above is successful.
    Somehow the order of the binded variable get messed up.
    Does anyone has any idea why?

    The datatype of X and Y are both VARCHAR2(10) in this case.
    Even if they are numbers, they have the same problem. The order get reversed and the data inserted is incorrect.
    E.g. I have column M VARCHAR2(10) and column N NUMBER (2) in TABLE2.
    String sql = "INSERT INTO TABLE2 (M, N) VALUES (?, ?)";
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setString(1, "one");
    ps.setInt(2, 1);
    ps.executeUpdate();
    The insert operation is still successful. But when you select it becomes,
    M N
    ? 0
    This is because the order of the variables get reversed again.
    Forgot to mention that if we have used Statement instead of PreparedStatement, we will not have such problem.
    E.g. Statement stmt = conn.createStatement();
    String sql = "INSERT INTO TABLE2 (M, N) VALUES ('one', 1)";
    stmt.executeUpdate(stmt);
    The above will insert fine and when we do a select, the result is correct.
    M N
    one 1
    Though the above works fine, I still prefer to use PreparedStatement because of performance issue. So anyone has any idea what exactly is happening?
    Hmmm, this ones a strange one.
    What type are X and Y in the database? If they are of
    type NUMBER why not try something like.
    ps.setInt(1, 1);
    OR
    ps.setLong(2, 2);
    and see if that makes any difference.

  • Table name as paramter to PreparedStatement?

    Can a table name be provided as a parameter to a Prepared Statement? We are using Oracle 10 and have data stored in different schemas. The tables in each schema are identical, but depending on the customer querying the database we need to view the data in one schema or another. Follows is the code we are using:
    Connection con = session.connection();           
    PreparedStatement stmt = con.prepareStatement("select * from ?");
    stmt.setString(1, customerSchema+".visit");
    ResultSet rs = stmt.executeQuery();and then we get the exception:
    ORA-00903: invalid table name
    Is what I am trying to do possible without reverting to changing the Prepared Statement call to:
    PreparedStatement stmt = con.prepareStatement("select * from " + customerSchema+ ".visit");The reason I would avoid the above code, is because we want to use Hibernate and use the mapping file for SQL statement, but the problem I have is SQL/JDBC focused, since Hibernate can't do something that JDBC can't do.
    BTW I am dealing with a legacy database, so while it would be nice to correct the database design, there is too much already in place to do so at this time.

    I am dealing with a system where each each client is allocated a separate schema (the data is not private to the customer, so no ethics issues here). We now need to create an admin tool that can create reports, grabbing the data from the various schemas. I was hopping to be able to have an admin user that can access all the schemas, without having to list all the login names and passwords somewhere. In doing so I would be able to query each table of a given type in the various tables. So if I have a table called 'MyTable', then we would have:
    SELECT * from mySchemaA.myTable
    SELECT * from mySchemaB.myTable
    etc
    While we can argue over what was done in the past over the way the database was set up, the truth its already there and we have to deal with the result.
    Currently the two alternative solutions I am looking at are:
    - separate JNDI entries, in the application server, that the application needs to know about
    - modifying the parameters in code prior to creating the PreparedStatement

  • How to insert an image file as blob using JDBC Statement

    Hi,
    I'm new on java.
    I want the code to insert an image file in Oracle database whose data type is blob.
    i want to use JDBC statement not the prepared statement.
    Please help me out.

    user8739226 wrote:
    thanks for the solution.
    I want to ask one thing
    let say i've created a method in a bean in which i'm passing three parameters.
    One is tablename as String, Second is Name of tablefields as Object, Third is Values as Object
    Like:
    public synchronized int insert(String table,Object[] fields, Object[] values)Ah now we're getting somewhere. I was trying to come up with a situation where using a regular Statement over PreparedStatement would be viable and came up with practically nothing.
    In the method body i'm accessing the table fields and values and combining them into the insert sql query.
    how can i do this using preparedstatment.
    how do i come to know here in this bean that this value is int or string or date at runtime to use setInt, setString, setdate or setBlob respectively.That's your problem. Bad design. You want to make some sort of universal insert method that can insert anything anywhere. But it doesn't really make sense, because whenever you're trying to insert something, you know exactly what you want to insert and where. You could use a PreparedStatement at that point (although encapsulate it in its own method). Now you're trying to create your own poorly designed framework over JDBC that doesn't solve problems, only increases them.
    Above was the only reason i saw, i was using statement instead of preparedstatment as statement was looking easy in this situation.
    please, give me the solution of above using preparedstatment.No, rather you should reconsider your design. What advantage does your insert() method give you over, let's say using a regular PreparedStatement. Granted, you can put your connection opening and other boilerplate code in the method. But if that's your only problem, then your insert method isn't gonna be much use. You could always switch to JPA for example and work with that.

  • Autogenerated key with Prepared Statement...

    Hi guys,
    i've a question and i need help...
    how can i retrieve autogenerated key with prepared Statement?
    I see examples only about statements...please post me example code..

    where i've to put STATEMENT.RETURN_GENERATED_KEYS?
    I need to use executeUpdate()...I didn't put it anywhere. I just called the getGeneratedKeys() method without using that constant anywhere and it just worked.

  • Error 01006 with prepared statement

    I have the 1006 error with the statement:
    prepstmt = conn.prepareStatement
    select col from table where col = '?'
    The parameter is set with setString().
    I tried with the oracle 815 and 817 drivers.

    where i've to put STATEMENT.RETURN_GENERATED_KEYS?
    I need to use executeUpdate()...I didn't put it anywhere. I just called the getGeneratedKeys() method without using that constant anywhere and it just worked.

  • MySql and PreparedStatement

    I am using WSAD 5.1 (Websphere Application Developer). My database is MySQL. I have set up a datasource that connects to MySQL in WSAD. I have a simple code that connects to the datasource using InitialContext.lookup.
    My Code :
    Connection conn = null;
    DataSource ds = null;
    try {
    InitialContext ctx = new InitialContext();
    ds = (DataSource)ctx.lookup("jdbc/ds1");     
    conn = ds.getConnection();
    } catch (NamingException e) {
    e.printStackTrace();
    //POINT 1
    PreparedStatement ps = conn.prepareStatement("select * from table1");
    ResultSet rs = ps.executeQuery( );
    rs.next();
    System.out.println("Value -> " + rs.getString(1));
    Error occurs at POINT 1. The error that im getting is this :
    java.sql.SQLException: Parameter with index of 1 is not set.
         at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.enforceStatementProperties(WSJdbcPreparedStatement.java:426)
         at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeQuery(WSJdbcStatement.java:429)
    The weird thing is, if I use Statement instead of PreparedStatement, it works. I dont know whats wrong. Please, anyone, help.
    By the way, I need to use PreparedStatement, because im planning to use the same method with different queries, so some have "?" and some dont.
    Please.     

    If it's the same code and the same database then your configurations aren't the same on the various machines. Make the machine where it "fails" (whatever that means) be configured the same way as the other machines where it doesn't.
    You mentioned Websphere, so making sure the configurations are the same is going to be ridiculously difficult. But that's what you need to do.

  • PreparedStatement and performance..

    <html>
    <b> Q1: Increases Network calls?? </b><br>
    <p> Where there is a table with large number columns , does a bind call to each column from a middle tier makes a network round-trip to the database?? Or does the Oracle JDBC driver cache binds to all columns and send them over in one call?? </p><br>
    <br>
    <b> Q2: Is the Statement faster then PreparedStatement for such large tables??</b><br>
    <p>If the answer to Q1 is yes, Will the recompilation needed by a Statement with values concatenated as literals in the SQL text beat the combined speed of such numerous bind calls ?? </p><br>
    <b> Q3. Recompilation of Statement Vs Oracle SQL Cache </b><br>
    <p> Are Q1 and Q2 moot ?? I.e If different values are concatenated to the Statement SQL text, does that in itself force Oracle to treat it as a different SQL or Has Oracle become advanced enough to treat literals as bind values and hence reuse a Statement cursor with diff. literal values executed in the past in the Cache?? </p><br>
    <br>
    <b> Q4. If Q3 is NO: PreparedStatement VS cached Cursor reuse </b><br>
    <p> If the anwser to Q3 is NO - i.e Statment is inefficient, then can we conclude that PreparedStatement offers double advantages. i.e. within the same session multiple executions are faster , since we only rebind. Also if the connection is closed and PreparedStatement is also closed , but the if same PreparedStatement is reopened in a new Session within the near future, Oracle will reuse the Cached statement, since the SQL text with place-holders('?' marks) definitely matches it. Whereas a Statememt with new literal values concatenated in is a new Statement for every new execution??</p><br>
    <br>
    <b> Q5. Is Q4 moot: PreparedStatement Vs mutiple Sessions </b><br>
    <p> Does closing and reopening a PreparedStatement force a recompilation of the statement anyways, so considerations of a cached Statement reuse is not a benefit for performance tuning here??</p><br>
    Please reply.
    </html>

    Sorry for the formatting messup:
    Q1: Increases Network calls??
    Where there is a table with large number columns , does a bind call to each column from a middle tier makes a network round-trip to the database?? Or does the Oracle JDBC driver cache binds to all columns and send them over in one call??
    Q2: Is the Statement faster then PreparedStatement for such large tables??
    If the answer to Q1 is yes, Will the recompilation needed by a Statement with values concatenated as literals in the SQL text beat the combined speed of such numerous bind calls ??
    Q3. Recompilation of Statement Vs Oracle SQL Cache
    Are Q1 and Q2 moot ?? I.e If different values are concatenated to the Statement SQL text, does that in itself force Oracle to treat it as a different SQL or Has Oracle become advanced enough to treat literals as bind values and hence reuse a Statement cursor with diff. literal values executed in the past in the Cache??
    Q4. If Q3 is NO: PreparedStatement VS cached Cursor reuse
    If the anwser to Q3 is NO - i.e Statment is inefficient, then can we conclude that PreparedStatement offers double advantages. i.e. within the same session multiple executions are faster , since we only rebind. Also if the connection is closed and PreparedStatement is also closed , but the if same PreparedStatement is reopened in a new Session within the near future, Oracle will reuse the Cached statement, since the SQL text with place-holders('?' marks) definitely matches it. Whereas a Statememt with new literal values concatenated in is a new Statement for every new execution??
    Q5. Is Q4 moot: PreparedStatement Vs mutiple Sessions
    Does closing and reopening a PreparedStatement force a recompilation of the statement anyways, so considerations of a cached Statement reuse is not a benefit for performance tuning here??
    Please reply.

Maybe you are looking for