Prepared Statement, executing  SELECT TOP in Ms Access

I'm having the following problem. I built an application fetching data without any problem from MS SQL Server, this was using prepared statements. Now i'm having this strange problem with the following query:
SELECT TOP 1 *
FROM table
WHERE appliance_id = ?
AND ttimestamp_initpk <= ?
AND ((Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?))
ORDER BY ttimestamp_initpk DESC
While on SQL Server this fetches just a record, on MS Access it fetches the whole set of records without worrying about TOP instruction.
That is, it acts like a SELECT * FROM, and this slows down runtime behaviour.
I'm using sun.jdbc.odbc.JdbcOdbcDriver, is it the problem?
Thanks, Mirko

Thanks for your answer, but i'm not sure this is the reason.
I made one more test: i wrote a .Net application connecting to a MS Access using an ODBC connection. SELECT TOP statement is working fine, so i think i'll try another JDBC driver. Any other solution??
Thanks,
Mirko

Similar Messages

  • Executiong prepared statement with Like% in SQL Query?

    Hi,
    We are developing GUI project.In which we need to retrieve the contract details based on the Name which we enter in eVision page.Here we will not enter the whole name,we will enter only the part of the name,for example if the actual name is Sun Seebeyond,I will enter only Su.So if there are five records in data base which starts the name with Su.Then it should return the five names..
    For this I am using the prepared statement as
    select name,contractid from table1 where name Like '?%'.
    Here my runtime input value will set to this parameter ?.When I execute this qry in my project I am getting error as "Unable to set parameters on the Object: Invalid parameter index 1".
    If I replace the ? with Su in query itself ,then it works fine..
    Please let me know is there any effective way,using which I can solve..
    Thanks,
    Renga.S.

    Hi,
    This option I already tried and it work fine too.
    I am looking for an option ,where we can handle with in the Query,so we dont need to write any code appending % into the actual valus.
    Thanks,
    Renga.S.

  • Prepared Statement nested calls (Oracle)

    I have a prepared statement like
    select type
    , id
    from ms_page_position where page_id =
    (select id from ms_url where url = ?)
    and column_id =
    (select id from ms_column where name = ?)
    and preview = ? order by position asc.
    If i place in
    pstmt.setString(1, "/news/");
    pstmt.setString(2, "RIGHTCOLUMN");
    pstmt.setString(3, "Y");
    res = pstmt.executeQuery();The three fields are strings
    i get this error -
    java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested.
    If i use a straight statement object and concatenate strings then i have no problem. Can you use prepared statements with nested selects - ?
    Cheers

    I've exactelly the same problem. Any ideas how to solve this. Concatenation works fine but two setString() on PS couses this exception.

  • Crash in oracle::occi::Statement::execute

    Hello,
    Application essentially:
    Environment *environment = Environment::createEnvironment(Environment::DEFAULT);
    Connection *connection  = environment->createConnection(...);
    Statement *statement   = connection->createStatement( < as below>);
    statement->setPrefetchMemorySize(0);
    statement->setPrefetchRowCount(100);
    statement->execute(); // crash occurs here
    Library v. 11.2.0.3, Linux, 64bit.
    My program works fine with Statement::execute("select FEATURE_UID from PSV_FIELDS");
    My program crashes with Statement::execute("select * from PSV_FIELDS");
    The application works fine with other tables
    Does anyone know what the problem is, is it in my code, in the library, somewhere else. And is there a way I can write this so that it works ?
    Best Regards,
    Even
    SQL> describe PSV_FIELDS
    Name                         Null? Type
    MI_PRINX                         NUMBER
    FEATURE_UID                    NOT NULL VARCHAR2(38)
    FIELD                              VARCHAR2(100)
    COUNTRY                         VARCHAR2(100)
    OPERATOR                         VARCHAR2(100)
    STATUS                          VARCHAR2(100)
    DISCOVERY_                         VARCHAR2(100)
    DEVELOPMEN                         VARCHAR2(100)
    PRODUCTION                         VARCHAR2(100)
    TYPE                              VARCHAR2(100)
    ABANDONED_                         VARCHAR2(100)
    FEATURE_GEOMETRY                    MDSYS.SDO_GEOMETRY
    This is the valgrind report
    ==4285== Invalid read of size 8
    ==4285== at 0xF435929: ttca2p (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xDC021F1: ttcfopr (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xF41602A: ttcdrv (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xF3BF480: nioqwa (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xF3AD190: upirtrc (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xF3B37E1: kpurcsc (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xF3B07D2: kpuexec (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xF3ADCCC: OCIStmtExecute (in /usr/lib64/oracle/11.2.0.3/client/lib64/libclntsh.so.11.1)
    ==4285== by 0xC0DC05C: oracle::occi::StatementImpl::doOCIExecute() (in /usr/lib64/oracle/11.2.0.3/client/lib64/libocci.so.11.1)
    ==4285== by 0xC0DBFE3: oracle::occi::StatementImpl::do_execute() (in /usr/lib64/oracle/11.2.0.3/client/lib64/libocci.so.11.1)
    ==4285== by 0xC0DBF97: oracle::occi::StatementImpl::execute(std::string const&) (in /usr/lib64/oracle/11.2.0.3/client/lib64/libocci.so.11.1)
    ==4285== by 0xC0DC2ED: oracle::occi::StatementImpl::executeQuery(std::string const&) (in /usr/lib64/oracle/11.2.0.3/client/lib64/libocci.so.11.1)
    ==4285== Address 0xb0 is not stack'd, malloc'd or (recently) free'd

    The problem was that the environment had to be created with Environment::OBJECT and not Environment::DEFAULT. An exception would have been nice though.
    Best Regards,
    Even

  • Problem with Prepared Statement & MS Access

    Hi
    I have tried to find some info about this but can't see anything specific to what I think the problem may be. Hopefully someone can point me in the right direction.I am trying to get information out of an MS Access database using a Prepared Statement but I am getting strange results.
    When I run the query in the database it gives me the correct totals (�51) for 4 records. When I run the Prepared Statement ,I get 81. Has it got anything to do with the data type I am using( sorry if this is a really basic question). here is my code- the connection etc is elsewhere.
    private void getReportMoneyTotal() throws SQLException
              Calendar todayTotal =Calendar.getInstance() ;
               SimpleDateFormat reportDateFormat = new SimpleDateFormat("dd MM yyyy");
              PreparedStatement preparedT =context.getConnection().prepareStatement(
                   "SELECT Sum(tblSession.Fee) AS Total, Count(tblBooking.BookingID) AS CountOfBookingID FROM tblSession INNER JOIN "+
                   "(tblBooking INNER JOIN tblCustomer_Booking ON tblBooking.BookingID = tblCustomer_Booking.BookingID) ON tblSession.SessionID = tblBooking.SessionID "+
                   "WHERE (((tblBooking.EventDate)>DateAdd('m',-1,#"+reportDateFormat.format(todayTotal.getTime())+"#)) AND ((tblSession.Session)='Morning' Or (tblSession.Session)='Evening')) OR (((tblSession.Session)='Afternoon') AND ((tblBooking.Extension)=Yes))"
              ResultSet resultTotal =preparedT.executeQuery();
              resultTotal.next();
              Double total =resultTotal.getDouble("Total");
              Locale locale = new Locale("GBP");
            NumberFormat gbpFormat = NumberFormat.getCurrencyInstance(locale);
              System.out.println(gbpFormat.format(total));
              preparedT.close();
         }I do realise that my code probably isn't very elegant but I'm only learning!

    Hi Matt--
    I am not clear if you are saving the url with the # # around
    the text or if
    the
    data already contains the # marks.
    When you insert a link, you want to make sure you insert is
    insert into table ( link1) values ( <cfqueryparam
    cfsqltype="cf_sql_varchar"
    value='#linkvaluehere#'> )
    remember to
    1) enclose your data's value inside quotes (some databases
    are picky about
    single v. double quotes).
    2) if it IS in quotes, swap doubles for singles and see if
    that helps.
    3) make sure your data being saved is NOT double hashed like
    '##linkvalueher##'. Double ##'s tell
    Coldfusion not to treat it as a variable.
    hope his helps,
    tami
    "Mattastic" <[email protected]> wrote in
    message
    news:f9c7h0$8ub$[email protected]..
    | Hi Folks,
    |
    | I'm storing a link in a nvarchar field in SQL server,
    www.foo.co.uk, it
    looks
    | and works fine in SQL server. Problem occurs when I setup
    an ADP in Access
    and
    | insert links. Certain links have a hash symbol around them.
    so
    |
    http://www.foo.co.uk, would be #
    http://www.foo.co.uk# which is
    causing
    problems.
    |
    | Can anyone tell me why this is happening? and how to stop
    it?
    |
    | Thankyou
    |

  • Invalid cursor state error while executing the prepared statement

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

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

  • SELECT-INTO prepared statement?

    Hi,
    I have a single-row select to execute. I don't know if the multi-row select functionality (ResultSets, etc.) should be used for a single-select.
    Here's from the Oracle JDBC Documentation on a prepared statement with input variables:
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into EMP (EMPNO, ENAME) values (?, ?)");
    pstmt.setInt (1, 1500); // The first ? is for EMPNO
    pstmt.setString (2, "LESLIE"); // The second ? is for ENAME
    pstmt.execute ();
    What I would like to do is have a PreparedStatement for output variables in a SELECT-INTO:
    pstmt= conn.prepareStatement("select max(sal) into ? from emp;");
    but there appears to be no bind variable functionality.
    Callable statements apparently are only for stored procedures.
    Basically, should I just use the multirow select for this?
    Thanks,
    Glen

    pstmt= conn.prepareStatement("select max(sal) into ?
    from emp;");
    but there appears to be no bind variable
    functionality.You might be able to bind this as an output parameter, but it seems like extra work (just getting a ResultSet for "select max(sal) from emp" would be a lot more straight forward).
    >
    Callable statements apparently are only for stored
    procedures.Not really, I execute PL/SQL blocks using prepared statements all the time. Sometimes it's the only way to get the data into a format that JDBC can handle.
    Here's an example:
        /** This is the SQL used to call the API ... */
        public static final String spSQL =  
        "declare " +
            "t_warranty_tbl apps.cib_devo_wrapper.wartbltyp; " +
            "x_warranty_tbl apps.cib_devo_wartbltyp; " +
            "x_return_text VARCHAR2(2000); " +
        "begin " +
            "apps.cib_devo_wrapper.cib_get_warranty_info(" +
                "P_SERIAL_NUMBER => ?,"
                "X_WARRANTY_TBL => t_warranty_tbl," +
                "X_RETURN_TEXT => x_return_text," +
                "x_row_count => ?); " +
            // Convert to a table of objects ...
            "x_warranty_tbl := apps.cib_devo_wrapper.cib_warranty_casttowartbltyp(t_warranty_tbl); " +
            // Get the cursor with order by ...
            "OPEN ? FOR SELECT * FROM TABLE(CAST(x_warranty_tbl AS apps.CIB_DEVO_WarTblTyp)) tbl " +
                "WHERE tbl.entitlementReturnCode != apps.cib_devo_wrapper.g_ent_ret_code_08 " +
                "ORDER BY tbl.INSTALLEDAT_CUSTOMER_NAME, tbl.SITE_NAME, tbl.SITE_ID, " +
                          "tbl.PRODUCT_FAMILY, tbl.PRODUCT_NAME, tbl.SERIAL_NUMBER; " +
           "?:=x_return_text; " +
        "end;";In this example, I declare a few variables, call a stored procedure,
    do some more PL/SQL to reduce the results before I finally bring them back.
    The first placeholder (question mark) is the input serial number, the second one is an output parameter that gives the row count. The third
    question mark is the cursor that contains the data I need, and the fourth is a reference to a status message.
    As you can see, the PL/SQL isn't exclusively stored procedure calls.
    >
    Basically, should I just use the multirow select for
    this?I think you'd need code that looks something like:
    DECLARE
    myCount NUMBER;
    BEGIN
    select max(sal) into myCount
    from emp;
    ? := myCount
    END;Although wrapping the select in a BEGIN..END block may be enough.

  • Prepared statement not releasing from access db

    Hello all,
    I have several prepared statements like the following:
    public void storeUpdate(String userId,String ws,String wm,String wl,String wx,String wxx,String bs,String bm,String bl,String bx,String bxx, String tq, String tp,Timestamp ts)
         String updatePurchase = "UPDATE store SET smallWhite=?,medWhite=?,lrgWhite=?,xlrgWhite=?,xxlrgWhite=?,smallBlue=?,medBlue=?,lrgBlue=?,xlrgBlue=?,xxlrgBlue=?,totalQty=?,totalPrice=?,ot=? WHERE playerNo='"+userId+"'";
         try{
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             objConn = java.sql.DriverManager.getConnection("jdbc:odbc:myDB","","");
             PreparedStatement ps = objConn.prepareStatement(updatePurchase);
             ps.setString(1, ws);
             ps.setString(2, wm);
             ps.setString(3, wl);
             ps.setString(4, wx);
             ps.setString(5, wxx);
             ps.setString(6, bs);
             ps.setString(7, bm);
             ps.setString(8, bl);
             ps.setString(9, bx);
             ps.setString(10, bxx);
             ps.setString(11, tq);
             ps.setString(12, tp);
             ps.setTimestamp(13,ts);
             ps.executeUpdate();
             ps.close();
             objConn.close();
                catch (SQLException s)
                    System.err.println("DataBase PROBLEM");
                    s.printStackTrace();
                catch (Exception e)
                        System.err.println("Error in updateStore method");
                        e.printStackTrace();
    } The prepared stmts seem to be "hanging on to" the access(dont laugh)table that the prepared stmt just updated. The reason I know this is because when I try to look at the table in access's design view I get a message saying:
    "Microsoft access
    You cant open the table 'store' for modification.
    A query or form bound to the table is open, you may not have permission to open this table in design view, or another user has the table open.
    If you have opened a query or form bound to this table, close it, and then try again to open the table in design view."
    The only way to open the table in design view is to shut down tomcat and restart.
    Should I be worried about this?
    Am i forgetting to close something in my ps?
    TIA!!

    I use PreparedStatement all the time with Access and never have a problem. The only thing I noticed about your code is that if an exception gets thrown in your method, the close statements won't get executed. This might leave the tables locked. You might want to try moving the close statements into a finally block. That way your statement and connection will get closed if an exception gets thrown or not.

  • Resultset from a batch select using prepared statement

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

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

  • Using a Prepared stat - Can a select SQL exist inside an Insert SQL

    Trying to insert values into the DB2UDB 7.1 database , using Prepared statement. I am getting a SQL exception as follows:
    SystemErr R java.sql.SQLException: Could not execute sql command - Original message: [IBM][CLI Driver][DB2] SQL0418N A statement contains a use of a parameter marker that is not valid. SQLSTATE=42610
    String reviewQuery = " INSERT INTO REVIEW (SUPLR_CD,STAT_CD,REVW_DATE,CREATE_UID) SELECT A.SUPLR_CD,?,CURRENT DATE,? FROM REV_CLAIMS A , SUPLR B
    WHERE A.SUPLR_CD = ? AND A.STAT_CD = ? and A.SUPLR_CD = B.SUPLR_CD
    sqlStmt =
    StatementFactory.getStatement(con,reviewQuery,BaseDAO.QUERY_DEBUG);
    sqlStmt.setString(1, statusCode);
    sqlStmt.setString(2, userId);
    sqlStmt.setString(3, supplierCode);
    sqlStmt.setString(4,reviewStatus);
    Can you please help me in solving this issue.
    Thanks,
    Ronhelp

    I guess that DB2 doesn't know your sql. You can try.
    String reviewQuery = " INSERT INTO REVIEW (SUPLR_CD,STAT_CD,REVW_DATE,CREATE_UID) SELECT A.SUPLR_CD,"+statusCode+",CURRENT DATE,"+userId+" FROM REV_CLAIMS A , SUPLR B
    WHERE A.SUPLR_CD = ? AND A.STAT_CD = ? and A.SUPLR_CD = B.SUPLR_CD
    sqlStmt =
    StatementFactory.getStatement(con,reviewQuery,BaseDAO.QUERY_DEBUG);
    sqlStmt.setString(1, supplierCode);
    sqlStmt.setString(2,reviewStatus);

  • Problem in inserting to MS Access using prepared statement

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

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

  • ALTERNATIVE FOR 'SELECT TOP STATEMENT

    HI FRIENDS
    IF ANY ONE KNOWS HOW TO CONVERT THE SQL STATEMENT GIVEN BELOW PLEASE HELP ME
    SELECT TOP 1 CardID FROM EasyRechargeMaster WHERE CardGroup = EasyRecharge.CardGroup
    THANKS & REGARDS

    Check this query. It should give you desired results....Are you sure about that? Does TOP 1 mean "whatever happens to be the first row fetched"?

  • Query slow when executing using prepared statement compared to sqlDeveloper

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

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

  • How to call method in JCD - which will execute prepared statement

    Hi All,
    I have a scenari where I have to call method in JCD, where in this method I have to execute prepared statement and return value.
    Please suggest me how to do this.
    Thanks & Regards,
    Anitha.B

    hi bolla,
    this is 100% java code. can you elaborate a little more what is your exact problem?
    i think your scenario is easy to accomlish.
    regards chris

  • Why does getdate() function return same time value for multiple select statements executed sequentially

    When I run the following code
    set nocount on
    declare @i table(id int identity(1,1) primary key, sDate datetime)
    while((select count(*) from @i)<10000)
    begin
    insert into @i(sDate) select getdate()
    end
    select top 5 sDate, count(id) selectCalls
    from @i
    group by sDate
    order by count(id) desc
    I get the following results. 
    sDate                   selectCalls
    2014-07-30 14:50:27.510 406
    2014-07-30 14:50:27.527 274
    2014-07-30 14:50:27.540 219
    2014-07-30 14:50:27.557 195
    2014-07-30 14:50:27.573 170
    As you can see the select getdate() function returned same time up to the milisecon 406 time for the first date value.  This started happening when we moved our applications to a faster server with four processors.  Is this correct or am I
    going crazy?
    Please let me know
    Bilal

    Observe that adding 2 ms is accurate only with datetime2.  As noted above, datetime does not have ms resolution:
    set nocount on
    declare @d datetime, @i int, @d2 datetime2
    select @d = getdate(), @i = 0, @d2 = sysdatetime()
    while(@i<10)
    begin
    select @d2, @d, current_timestamp, getdate(), sysdatetime()
    select @d = dateadd(ms,2,@d), @i = @i+1, @d2=dateadd(ms,2,@d2)
    end
    2014-08-09 08:36:11.1700395 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1720395 2014-08-09 08:36:11.173 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1740395 2014-08-09 08:36:11.177 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1760395 2014-08-09 08:36:11.180 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1780395 2014-08-09 08:36:11.183 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1800395 2014-08-09 08:36:11.187 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    DATE/TIME functions:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Maybe you are looking for

  • Multi language AddOn

    Multi language AddOn I will like to know were can I find information on how to make a AddOn multi language available. Best regards. Edited by: Jose Villarreal on Apr 21, 2008 5:27 PM

  • Turning sound off on camera shutter?

    completely new to Droid here.  I have looked every where for something that will turn the shutter sound off of the camera when taking pictures.  Anyone have a clue?

  • How to move my palm to another laptop

    I've recently bought a new laptop that has Windows 8.1 and I want to put my Palm Tungsten e on to it. Previously it has been on Windows 7 on my old laptop (it's still on there at the moment) I'm not very good on computers so can anyone give me a step

  • Why am I getting == instead of equals() behaviour when I add to a HashSet?

    I want to maintain a set of ordered pairs. I have created a generic class OrderedPair<K,V>, and given it the following equals method:     public boolean equals (OrderedPair<K,V> otherGuy) {      return otherGuy != null && this.key.equals(otherGuy.key

  • How to remove leading zero in a inputfield

    I have a inputfield UI element which is bind to a NUM type context.  When it display a number, it always come with leading zero, like '001'. Can anyone teach me how to remove the leading zero.