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);

Similar Messages

  • How can I use an IF statement in the SELECT

    Hi People,
    I have a procedure called ENQUEUE_PROC which takes 3 parameters.
    and I am trying to use an if statement in the select. I appreciate the help with this task.
    here is my code.
    Please have a look at my Select statement. What I have does not compile, however it might give you an idea of what i need.
    PROCEDURE ENQUEUE_PROC(P_SUBMISSION_ID NUMBER,
                           P_EVENT         VARCHAR2,
                                CASE_TYPE_CODE NUMBER;
                           ) AS
         XMLDATA XMLTYPE;
         enqueue_options     dbms_aq.enqueue_options_t;
         message_properties  dbms_aq.message_properties_t;
         message_handle      RAW(16);
         message SYS.AQ$_JMS_TEXT_MESSAGE;
    BEGIN
              SELECT      
                        XMLELEMENT("caseFileEvent", XMLATTRIBUTES('http://www.ussc.gov/soa/casefile/event/types' AS "xmlns",
                                                          'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns:ns0"),
                             XMLELEMENT("caseFileUploadEvent", XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi",
                                                                                                   'http://www.ussc.gov/soa/casefile/event/types ../xsd/Case_META.xsd' AS "xsi:schemaLocation",
                                                                                                   'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns"),
                                       XMLELEMENT("taskEvent", P_EVENT), --eg - 'SUBMIT', 'REJECT', 'RESUBMIT'
                                XMLELEMENT("defendentDetails",
                                                                XMLELEMENT("sentensingDate", SMD.SENT_VIO_DATE),
                                                                XMLELEMENT("personDetails",
                                                                               // Here is where I want my IF statement, *********************************
                                                                               IF CASE_TYPE_CODE = 10 THEN
                                                                                         XMLELEMENT("personNameDetails",
                                                                                                             XMLELEMENT("firstName", SMD.FIRST_NAME),
                                                                                                             XMLELEMENT("middleName", SMD.MIDDLE_NAME),
                                                                                                             XMLELEMENT("lastName", SMD.LAST_NAME)
                                                                                                   ), -- personNameDetails
                                                                               ELSE
                                                                                    XMLELEMENT("personNameDetails",
                                                                                                   XMLELEMENT("corpname", SMD.CORPNAME),
                                                                                         ), -- personNameDetails
                                                                               XMLELEMENT("dateOfBirth", SMD.BIRTH_DATE)          
                                                                          ) -- personDetails
                                            ), -- defendentDetails
                                            XMLELEMENT("documentStatusDetails",
                                                      XMLELEMENT("otherStatus",
                                                                     XMLELEMENT("intCode", NULL),
                                                                     XMLELEMENT("description", NULL)
                                                                ) -- otherStatus
                                            ), -- documentStatusDetails
                                            XMLELEMENT("uploadOtherDetails",
                                                           XMLELEMENT("submissionId", SUB.SUBMISSION_ID),
                                                           XMLELEMENT("submissionSessionId", SUB.SUB_SESSION_ID),
                                                           XMLELEMENT("submissionMethod",
                                                                XMLELEMENT("intCode", SUB.SUB_MTHD_CODE),
                                                                XMLELEMENT("description", SM.DESCRIP)
                                                           ), -- submissionMethod
                                                           XMLELEMENT("submissionReason",
                            XMLELEMENT("intCode", SUB.SUB_TYPE_CODE),
                                                                XMLELEMENT("description", SR.DESCRIP)
                                                           ), -- submissionReason
                                                           XMLELEMENT("district",
                                                                XMLELEMENT("intCode", SMD.DIST_ID),
                                                                XMLELEMENT("description", D.DISTRICT_NAME)
                                                           ), -- district
                                                           XMLELEMENT("caseFileType",
                                                                XMLELEMENT("intCode", SUB.CASE_TYPE_CODE),
                                                                XMLELEMENT("description", C.DESCRIP)
                                                           ), -- caseFileType
                                                           XMLELEMENT("primaryDocketInfo",
                                                                XMLELEMENT("yearYY", SUBSTR(SMD.DOCKET, 1, 2)),
                                                                XMLELEMENT("id", SUBSTR(SMD.DOCKET, 3, 7)),
                                                                XMLELEMENT("defendentNumber", SMD.DEF_NUM)
                                                           ), -- primaryDocketInfo
                                                           XMLELEMENT("PACTSId", SMD.PACTS_ID), -- PACTSId
                                                           XMLELEMENT("AOJudgeId",
                                                                XMLELEMENT("intCode", SMD.AO_JUDGE_ID),
                                                                XMLELEMENT("description", J.LAST_NAME || ', ' || J.FIRST_NAME || ', ' || J.MIDDLE_NAME)
                                                           ), -- AOJudgeId
                                                           XMLELEMENT("missingCasefile", SUB.MISSING_CASE), -- missingCasefile
                                                           XMLELEMENT("creator",
                                                                XMLELEMENT("firstName", NULL),
                                                                XMLELEMENT("lastName", NULL),
                                                                XMLELEMENT("email", SUB.CREATOR_ID),
                                                                XMLELEMENT("actionDate", REGEXP_REPLACE( TO_CHAR(SUB.CREATE_TIME, 'YYYY-MM-DD"T"HH24:MI:SS.FFTZR'), '...(......)$', '\1'))
                                                           ), -- creator
                                                           XMLELEMENT("lastModifier",
                                                                XMLELEMENT("firstName", NULL),
                                                                XMLELEMENT("lastName", NULL),
                                                                XMLELEMENT("email", H.USER_ID),
                                                                XMLELEMENT("actionDate", TO_CHAR(H.ACTION_DATE, 'YYYY-MM-DD"T"HH24:MI:SS".000-05:00"'))
                                                           ) -- lastModifier
                                            ) -- uploadOtherDetails
                             ) -- caseFileUploadEvent
                        ) -- caseFileEvent
              INTO      XMLDATA
              FROM      USSC_CASES.SUBMISSION SUB,
              USSC_CASES.SUBMISSION_METADATA SMD,
              USSC_CASES.CASE_HISTORY H,
              LOOKUP.CASE_SUB_MTHD SM,
              LOOKUP.CASE_SUB_TYPE SR,
              LOOKUP.DISTRICTS D,
              LOOKUP.JUDGES J,
              LOOKUP.CASE_TYPES C
              WHERE      SUB.SUBMISSION_ID = SMD.SUBMISSION_ID
              AND        SUB.SUBMISSION_ID = H.SUBMISSION_ID
              AND        SUB.SUB_MTHD_CODE = SM.SUBMTHD_CODE
              AND        SUB.SUB_TYPE_CODE = SR.SUBTYPE_CODE
              AND        SUB.CASE_TYPE_CODE = C.CASE_TYPE_CODE
              AND        SMD.DIST_ID = D.USSC_DISTRICT_ID
              AND        SMD.AO_JUDGE_ID = J.AO_JUDGE_ID
              AND        H.ACTION_DATE IN (SELECT MAX(A.ACTION_DATE)
                                  FROM USSC_CASES.CASE_HISTORY A
                                  WHERE A.SUBMISSION_ID = P_SUBMISSION_ID)
              AND        SUB.SUBMISSION_ID = P_SUBMISSION_ID;
        --dbms_output.put_line('queue start '|| xmldata.getclobval());
        --insert into test1 values(xmldata);
        message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
        message.set_text(xmldata.getStringVal());
        DBMS_AQ.ENQUEUE(queue_name => 'case_file_queue',  -- aqadm.cases_queue             
        enqueue_options    => enqueue_options,       
        message_properties => message_properties,     
        payload  => message,             
        msgid   => message_handle);
         COMMIT;
    END ENQUEUE_PROC;

    thanks for the help,
    I believe I almost got it to compilw, however I am getting Error(29,19): PL/SQL: ORA-00918: column ambiguously defined.
    Of course CASE_TYPE_CODE is ambiguously because its passed in, is there a way around this.
    Here is what i have so far.
    PROCEDURE ENQUEUE_PROC(P_SUBMISSION_ID NUMBER,
                           P_EVENT         VARCHAR2,
                           CASE_TYPE_CODE NUMBER    // passed in field
                           ) AS
         XMLDATA XMLTYPE;
         enqueue_options     dbms_aq.enqueue_options_t;
         message_properties  dbms_aq.message_properties_t;
         message_handle      RAW(16);
         message SYS.AQ$_JMS_TEXT_MESSAGE;
    BEGIN
              SELECT      
                        XMLELEMENT("caseFileEvent", XMLATTRIBUTES('http://www.ussc.gov/soa/casefile/event/types' AS "xmlns",
                                                          'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns:ns0"),
                             XMLELEMENT("caseFileUploadEvent", XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi",
                                                                                                   'http://www.ussc.gov/soa/casefile/event/types ../xsd/Case_META.xsd' AS "xsi:schemaLocation",
                                                                                                   'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns"),
                                       XMLELEMENT("taskEvent", P_EVENT), --eg - 'SUBMIT', 'REJECT', 'RESUBMIT'
                                            XMLELEMENT("defendentDetails",
                                                                XMLELEMENT("sentensingDate", SMD.SENT_VIO_DATE),
                                                                CASE
                                                                     WHEN CASE_TYPE_CODE = 10 THEN
                                                                           XMLELEMENT("personDetails",
                                                                                         XMLELEMENT("personNameDetails",
                                                                                                             XMLELEMENT("firstName", SMD.FIRST_NAME),
                                                                                                             XMLELEMENT("middleName", SMD.MIDDLE_NAME),
                                                                                                             XMLELEMENT("lastName", SMD.LAST_NAME)
                                                                                                   ), -- personNameDetails 
                                                                                         XMLELEMENT("dateOfBirth", SMD.BIRTH_DATE)          
                                                                                    ) -- personDetails
                                                                     ELSE
                                                                          XMLELEMENT("corporationDetails",
                                                                                         XMLELEMENT("organizationName", SMD.CORP_NAME)
                                                                                    ) -- corporationDetails          
                                                                END
                                            ), -- defendentDetails
                                            XMLELEMENT("documentStatusDetails",
                                                      XMLELEMENT("otherStatus",
                                                                     XMLELEMENT("intCode", NULL),
                                                                     XMLELEMENT("description", NULL)
                                                                ) -- otherStatus
                                            ), -- documentStatusDetails
                                            XMLELEMENT("uploadOtherDetails",
                                                           XMLELEMENT("submissionId", SUB.SUBMISSION_ID),
                                                           XMLELEMENT("submissionSessionId", SUB.SUB_SESSION_ID),
                                                           XMLELEMENT("submissionMethod",
                                                                XMLELEMENT("intCode", SUB.SUB_MTHD_CODE),
                                                                XMLELEMENT("description", SM.DESCRIP)
                                                           ), -- submissionMethod
                                                           XMLELEMENT("submissionReason",
                                                                XMLELEMENT("intCode", SUB.SUB_TYPE_CODE),
                                                                XMLELEMENT("description", SR.DESCRIP)
                                                           ), -- submissionReason
                                                           XMLELEMENT("district",
                                                                XMLELEMENT("intCode", SMD.DIST_ID),
                                                                XMLELEMENT("description", D.DISTRICT_NAME)
                                                           ), -- district
                                                           XMLELEMENT("caseFileType",
                                                                XMLELEMENT("intCode", SUB.CASE_TYPE_CODE),
                                                                XMLELEMENT("description", C.DESCRIP)
                                                           ), -- caseFileType
                                                           XMLELEMENT("primaryDocketInfo",
                                                                XMLELEMENT("yearYY", SUBSTR(SMD.DOCKET, 1, 2)),
                                                                XMLELEMENT("id", SUBSTR(SMD.DOCKET, 3, 7)),
                                                                XMLELEMENT("defendentNumber", SMD.DEF_NUM)
                                                           ), -- primaryDocketInfo
                                                           XMLELEMENT("PACTSId", SMD.PACTS_ID), -- PACTSId
                                                           XMLELEMENT("AOJudgeId",
                                                                XMLELEMENT("intCode", SMD.AO_JUDGE_ID),
                                                                XMLELEMENT("description", J.LAST_NAME || ', ' || J.FIRST_NAME || ', ' || J.MIDDLE_NAME)
                                                           ), -- AOJudgeId
                                                           XMLELEMENT("missingCasefile", SUB.MISSING_CASE), -- missingCasefile
                                                           XMLELEMENT("creator",
                                                                XMLELEMENT("firstName", NULL),
                                                                XMLELEMENT("lastName", NULL),
                                                                XMLELEMENT("email", SUB.CREATOR_ID),
                                                                XMLELEMENT("actionDate", REGEXP_REPLACE( TO_CHAR(SUB.CREATE_TIME, 'YYYY-MM-DD"T"HH24:MI:SS.FFTZR'), '...(......)$', '\1'))
                                                           ), -- creator
                                                           XMLELEMENT("lastModifier",
                                                                XMLELEMENT("firstName", NULL),
                                                                XMLELEMENT("lastName", NULL),
                                                                XMLELEMENT("email", H.USER_ID),
                                                                XMLELEMENT("actionDate", TO_CHAR(H.ACTION_DATE, 'YYYY-MM-DD"T"HH24:MI:SS".000-05:00"'))
                                                           ) -- lastModifier
                                            ) -- uploadOtherDetails
                             ) -- caseFileUploadEvent
                        ) -- caseFileEvent
              INTO      XMLDATA
              FROM      USSC_CASES.SUBMISSION SUB,
              USSC_CASES.SUBMISSION_METADATA SMD,
              USSC_CASES.CASE_HISTORY H,
              LOOKUP.CASE_SUB_MTHD SM,
              LOOKUP.CASE_SUB_TYPE SR,
              LOOKUP.DISTRICTS D,
              LOOKUP.JUDGES J,
              LOOKUP.CASE_TYPES C
              WHERE      SUB.SUBMISSION_ID = SMD.SUBMISSION_ID
              AND        SUB.SUBMISSION_ID = H.SUBMISSION_ID
              AND        SUB.SUB_MTHD_CODE = SM.SUBMTHD_CODE
              AND        SUB.SUB_TYPE_CODE = SR.SUBTYPE_CODE
              AND        SUB.CASE_TYPE_CODE = C.CASE_TYPE_CODE
              AND        SMD.DIST_ID = D.USSC_DISTRICT_ID
              AND        SMD.AO_JUDGE_ID = J.AO_JUDGE_ID
              AND        H.ACTION_DATE IN (SELECT      MAX(A.ACTION_DATE)
                                                 FROM      USSC_CASES.CASE_HISTORY A
                                                 WHERE      A.SUBMISSION_ID = P_SUBMISSION_ID)
              AND        SUB.SUBMISSION_ID = P_SUBMISSION_ID;
        --dbms_output.put_line('queue start '|| xmldata.getclobval());
        --insert into test1 values(xmldata);
        message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
        message.set_text(xmldata.getStringVal());
        DBMS_AQ.ENQUEUE(queue_name => 'case_file_queue',  -- aqadm.cases_queue             
        enqueue_options    => enqueue_options,       
        message_properties => message_properties,     
        payload  => message,             
        msgid   => message_handle);
         COMMIT;
    END ENQUEUE_PROC;Edited by: Rooney on Jan 31, 2012 1:55 PM

  • Use of Prepared Statement in adf

    Hi Experts,
    I am confused with the Use of prepared statement in adf.
    My use case is ,
    I have to update a table from every page in my application under certain conditions.
    My question is ,
    whether I have to create the VO iterator binding in every page and by calling the createinsert and insert the data in to the table or
    use a common method in the Application module impl
    which is using a prepared statement,(which is not even creating the ViewObject ) like
    PreparedStatement st = null;
    String sql = "INSERT INTO hr.departments (DEPARTMENT_ID,    DEPARTMENT_NAME,   MANAGER_ID,   LOCATION_ID) VALUES (seq,?,?,?)";
                st=getDBTransaction().createPreparedStatement(sql,0);
                st.setString(1, name);
                st.setString(2, mgr_id);
                st.setString(3, Loc_id);
                st.execute();
    getDBTransaction().commit();which is the best approach?
    Studio Edition Version 11.1.1.2.0
    Ranjith

    Ranjith,
    Without further understanding the use case, there's not really much difference between the two approaches. In both cases, you'd have a binding in the page definition (either an iterator binding for the VO or a method binding for the AM service method). Both will use bind variables. The main difference I can see is that, depending on how you have configured your AM pooling settings, the VO method will incur fewer parses in the DB because the AM will cache prepared statements for you.
    John

  • What happen if i use controll break statement in between select & endselect

    Hi all,
    what happen if i use controll break statement in between select & endselect ?
    Thanks in Advance
    KR

    Hi for reference u can go through this code example
    data:
      fs_tab like sflight.
      data:
       t_tab like standard table of fs_tab.
       select * from sflight into table t_tab.
       loop at t_tab into fs_tab.
         write: / fs_tab-carrid.
       endloop.
       refresh t_tab.
       clear fs_tab.
       select * from sflight into fs_tab.
         at new fs_tab-carrid.
           append fs_tab to t_tab.
         endat.
       endselect.

  • How can I select the existing worksheet while using OLE2 to open the template workboo

    Source:
    application:=ole2.create_obj('Excel.Application');
    workbooks:=ole2.get_obj_property(application,'Workbooks');
    args := ole2.create_arglist;
    ole2.add_arg(args, 'c:\RptTemplate.xlt');
    workbook:=ole2.invoke_obj(workbooks,'Open',args);
    ole2.destroy_arglist(args);
    worksheets:=ole2.get_obj_property(application,'Worksheets');
    args := ole2.create_arglist;
    ole2.add_arg(args, 'Sheet1');      
    worksheet     :=ole2.invoke_obj(worksheets,'Select',args);
    ole2.destroy_arglist(args);
    Problem:
    1. While executing the above code, error -305500 occurs after executing "worksheet := ole2.invoke_obj(worksheets','Select',args)". How can I select the sheet i wanted in the template ??
    2. As I refer to the forms on-line document, it stated that the ole2 programmers documentation can provide all object types and methods that can be used with the OLE2. Does any link can provided to download the specified documentation ??

    The error is probably that your Worksheets variable is actually empty. Looking at your code I think the problem is that you try and get the value of the worksheets collection from the application then you should try and get it from the Workbooks object.

  • Using case when statement in the select query to create physical table

    Hello,
    I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
    I have a physical table based on a select table with one column.
    SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
    I also have a customer table.
    In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
    In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
    EXECUTION
    When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
    everything works as expected. YE!!
    Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
    SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
    FROM DUAL
    Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
    surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
    SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
    If anyone has any explanation to this error and how we can achieve the same, please help.
    Thanks.

    Hello,
    Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
    I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
    Here is what I am trying to do. the select query of the physical table is as follows.
    SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
    The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
    Thanks.

  • What prepared statement can do?

    Hello I got this question:
    Normal usage of PreparedStatement goes like this:
    PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?");
    pstmt.setBigDecimal(1, 153833.00)
    pstmt.setInt(2, 110592)
    My problem is how can I use it for INSERT statement??
    e.g. I want to do something like this:
    PreparedStatement pstmt = con.INSERT INTO TABLE_A VALUE('?','?','?',?);
    byte[] bytes;
    pstmt.setString(1, "1234");
    pstmt.setBytes(2,bytes);
    but I got an error for that..so I suspect my usage is somehow wrong. Can someone teach me how to do this kind of insertion using preparedStatement?
    Thanks,

    HI Bvsp_Indian,
    thanks for the insertion part and it works, however, when I try to retrieve the same bytes it gives me this error
    Error: JZ0TC: Attempted conversion between an illegal pair of types.
    java.sql.SQLException: JZ0TC: Attempted conversion between an illegal pair of ty
    pes.
    at com.sybase.jdbc.ErrorMessage.raiseError(ErrorMessage.java)
    at com.sybase.tds.TdsJdbcInputStream.getBytes(TdsJdbcInputStream.java)
    at com.sybase.jdbc.SybResultSet.getBytes(SybResultSet.java)
    at com.sybase.jdbc.SybResultSet.getBytes(SybResultSet.java)
    My codes on how to retrive the result set goes like this:
    String strSelect = "SELECT * FROM testing where NAME_CUSTOMER = 'Thomas'";
    java.sql.ResultSet rs1 = stmt.executeQuery(strSelect);
    while (rs1.next()) {
    String name = rs1.getString("NAME_CUSTOMER");
    String age1 = rs1.getString("AGE");
    //String credit_no = rs1.getString("CREDIT_NUMBER");
    // this is the column that i want to retrieve to its bytes[]
    byte[] secret = rs1.getBytes("SECRET");
    System.out.println("THE SECRET IS " + secret);     
    How can I retrieve back the bytes[] that i just stored??
    Thanks in advance,

  • Using BT Keyboard (A1314) - Can't Select Multiple Items

    Recently bought Mini and separately purchased a BT KB. When I use the command key to select multiple items, I can't. Whichever item I click on while holding the command button, it just selects that item, not the group.
    Also when holding down the 'shift' key, I cannot select items in sequence. I have looked in prefs, but nothing having to do with this issue.
    Anyone have any ideas?
    Thanks!

    Try resetting the PRAM.
    Click here for instructions.

  • Prepared Statement - Help pl

    Hi!
    Is there any disadvantage in using a Prepared statement to insert records in to the database.What is the difference in using Prepared Statement compared to Statement.Any disadavantage?I know the advantage of using Prepared statement where by I can insert values with special characters.Any disadavantage of using Prepared statement regularly?Please explain.Thanks

    hello all, i like the statement that some of u guys posting here..
    i have a puzzle here, if i have more than one query to table, lets say 3rd query are depends on result of 2nd query which taken from 1st query result.
    should i use prepared statement instead of statement? can we say that using of prepared statement can make our query result faster than using statement??
    i have a function here which goes well when using statement st,
    public void getMainlevelBcat(String loggedbizid){
    String query = " SELECT DISTINCT category2.mainlevel FROM bizcategory2, category2 "+
    " WHERE bizcategory2.catid = category2.catid "+
    " AND bizcategory2.bizid ='"+loggedbizid+"' ";
    try {
    st = con.createStatement();
    rs =st.executeQuery(query);
    catch (SQLException e) {
    System.out.println(e.getMessage());
    can anybody chance it to new function using prepared statement??

  • Handling ' and " in a Prepared Statement

    Hi,
    I am using a prepared statement (WebLogic Portal Server having JDBC communication with MS SQL server)
    I HAVE to pass a string like '"*ABC*"'
    i.e. <single quote><double quote>*ABC<double quote><single quote>
    If i hard code this value within the prepared statement it works.
    If i try to pass it as argument it fails.
    In my case the user may submit any string value in the place of ABC
    Kindly advise
    regards
    -Ramudu

    You're probably trying to include the quotes in the prepared statement and pass the ABC as the text to substitute for the question mark. It doesn't really work like that. It's all or nothing. Create your parameter like this:
    public String quoteWrapper(final String unwrappedParameter) {
       return "'\"*"+unwrappedParameter+"*\"'";
    }

  • Can not use prepared statement

    i am using a prepared statement for the following query but the query does not give me an output where as if i use a create statement i am getting my result
    can any one say why is it ? or what the problem is
                String strQuery = " select lic.lic_id  licId, "+                                                   " lic.license_nbr licNo, "+                                                   " lt.display_desc licType "+                                                   " from colamgr.cola_entities ent, "+                                                 " colamgr.cola_licenses lic, "+                                                 " colamgr.cola_lic_types lt, "+                                                 " colamgr.cola_boards    boa "+                                           " where (( 'E'= ? and ent.ent_id = ?) "+                                           " or ( 'L'= ? and lic.lic_id = ?)) "+                                           " and lic.ent_id = ent.ent_id "+                                           " and lic.license_status ='ACTIVE' "+                                           " and lic.lt_id = lt.lt_id "+                                           " and boa.boa_id = lt.boa_id "+                                           " and (( 'E' = ? and (lt.print_ent_addr_ind <> 'N' "+                                           " or (lt.print_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                           " or  ( 'L' = ? and lt.print_lic_addr_ind <> 'N')) "+                                           " UNION "+                                           " select  empl_lic.lic_id  licId, "+                                                   " empl_lic.license_nbr licNo, "+                                                   " empl_lt.display_desc licType "+                                                                                     " from colamgr.cola_entities  ent, "+                                                 " colamgr.cola_licenses  lic, "+                                                 " colamgr.cola_lic_types lt, "+                                                 " colamgr.cola_lic_xrefs lx, "+                                                 " colamgr.cola_licenses  empl_lic, "+                                                 " colamgr.cola_lic_types empl_lt, "+                                                 " colamgr.cola_boards    empl_boa "+                                           " where (( 'E'= ? and ent.ent_id = ?) "+                                           " or ( and lic.lic_id = ? and 'L'= ? )) "+                                           " and lic.ent_id              = ent.ent_id "+                                           " and lic.lic_id              = lx.lic_id "+                                           " and lic.license_status      ='ACTIVE' "+                                           " and lx.approval_ind        = 'A' "+                                           " and lx.begin_date          is not null "+                                           " and lx.end_date            is null "+                                           " and lx.lic_id_child        = empl_lic.lic_id "+                                           " and empl_lt.lt_id          = empl_lic.lt_id "+                                           " and empl_boa.boa_id        = empl_lt.boa_id "+                                           " and empl_lic.license_status = 'ACTIVE' "+                                           " and lic.lt_id              = lt.lt_id "+                                           " and exists (select 1 "+                                                       " from colamgr.cola_lic_types lt1 "+                                                       " where lt1.lt_id = empl_lic.lt_id "+                                                       " and ((lt1.xref1_ind in ('M') "+                                                       " and  lt1.xref1_lt_id = lt.lt_id "+                                                       " and  (('E'= ? and (lt1.print_xref1_ent_addr_ind <> 'N' "+                                                       " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                                       " or    ( 'L' = ? and lt1.print_xref1_lic_addr_ind <> 'N'))) "+                                                       " or  (lt1.xref2_ind in ('M') "+                                                       " and  lt1.xref2_lt_id = lt.lt_id "+                                                       " and  (('E'= ? and (lt1.print_xref2_ent_addr_ind <> 'N' "+                                                       " or (lt1.print_xref2_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                                       " or    ( 'L' = ? and lt1.print_xref2_lic_addr_ind <> 'N'))) "+                                                       " or  (lt1.xref1_ind in ('O') "+                                                       " and  (lt1.xref1_lt_id = lt.lt_id or lt1.xref2_lt_id = lt.lt_id) "+                                                       " and  (('E'= ? and (lt1.print_xref1_ent_addr_ind <> 'N' "+                                                       " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+                                                       " or    ('L' = ? and lt1.print_xref1_lic_addr_ind <> 'N'))))) "+                                                       " order by 6 desc, 7 asc ";

    here is my code which works . when i replace the ? ( where i am checking strAddrtype ='L' using set string it doesn't work . i wanted to know why its not working any help is much appreciated.
    thanks .
            public ArrayList getReprintLicenses(String strEntId, String strLicId, String strAddrType)
              ArrayList alMasterLicList = new ArrayList();
               String strQuery = " select lic.lic_id   licId, "+
                                                     " lic.license_nbr licNo, "+
                                                     " lt.display_desc licType, "+
                                                     " colamgr.COLA_CHK_RENEW_STAT(lic.lic_id) renewStatus, "+
                                                     " 0, "+
                                                     " SUBSTR(lic.License_nbr,1,4), "+
                                                     " SUBSTR(lic.License_nbr,5) "+
                                              " from cola_entities ent, "+
                                                   " cola_licenses lic, "+
                                                   " cola_lic_types lt, "+
                                                   " cola_boards    boa "+
                                              " where ((?= 'E' and ent.ent_id = ? ) "+
                                              " or ("+strAddrType+" = 'L' and lic.lic_id = ?)) "+
                                              " and lic.ent_id = ent.ent_id "+
                                              " and lic.license_status ='ACTIVE' "+
                                              " and lic.lt_id = lt.lt_id "+
                                              " and boa.boa_id = lt.boa_id "+
                                              " and ((?= 'E' and (lt.print_ent_addr_ind <> 'N' "+
                                              " or (lt.print_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                              " or   ("+strAddrType+" = 'L' and lt.print_lic_addr_ind <> 'N')) "+
                                              " UNION "+
                                              " select  empl_lic.lic_id  licId, "+
                                                      " empl_lic.license_nbr licNo, "+
                                                      " empl_lt.display_desc licType, "+
                                                      " COLA_CHK_RENEW_STAT(empl_lic.lic_id) renewStatus, "+
                                                      " 1, "+
                                                      " SUBSTR(lic.License_nbr,1,4), "+
                                                      " SUBSTR(lic.License_nbr,5) "+
                                              " from cola_entities  ent, "+
                                                   " cola_licenses  lic, "+
                                                   " cola_lic_types lt, "+
                                                   " cola_lic_xrefs lx, "+
                                                   " cola_licenses  empl_lic, "+
                                                   " cola_lic_types empl_lt, "+
                                                   " cola_boards    empl_boa "+
                                              " where ((? = 'E' and ent.ent_id =?) "+
                                              " or ("+strAddrType+" = 'L' and lic.lic_id =?)) "+
                                              " and lic.ent_id              = ent.ent_id "+
                                              " and lic.lic_id              = lx.lic_id "+
                                              " and lic.license_status      ='ACTIVE' "+
                                              " and lx.approval_ind         = 'A' "+
                                              " and lx.begin_date           is not null "+
                                              " and lx.end_date             is null "+
                                              " and lx.lic_id_child         = empl_lic.lic_id "+
                                              " and empl_lt.lt_id           = empl_lic.lt_id "+
                                              " and empl_boa.boa_id         = empl_lt.boa_id "+
                                              " and empl_lic.license_status = 'ACTIVE' "+
                                              " and lic.lt_id               = lt.lt_id "+
                                              " and exists (select 1 "+
                                                          " from cola_lic_types lt1 "+
                                                          " where lt1.lt_id = empl_lic.lt_id "+
                                                          " and ((lt1.xref1_ind in ('M') "+
                                                          " and  lt1.xref1_lt_id = lt.lt_id "+
                                                          " and  ((? = 'E' and (lt1.print_xref1_ent_addr_ind <> 'N' "+
                                                          " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                                          " or    (?= 'L' and lt1.print_xref1_lic_addr_ind <> 'N'))) "+
                                                          " or   (lt1.xref2_ind in ('M') "+
                                                          " and  lt1.xref2_lt_id = lt.lt_id "+
                                                          " and  ((?= 'E' and (lt1.print_xref2_ent_addr_ind <> 'N' "+
                                                          " or (lt1.print_xref2_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                                          " or    (? = 'L' and lt1.print_xref2_lic_addr_ind <> 'N'))) "+
                                                          " or   (lt1.xref1_ind in ('O') "+
                                                          " and   (lt1.xref1_lt_id = lt.lt_id or lt1.xref2_lt_id = lt.lt_id) "+
                                                          " and  ((? = 'E' and (lt1.print_xref1_ent_addr_ind <> 'N' "+
                                                          " or (lt1.print_xref1_lic_addr_ind <> 'N' and lic.addr1 is null))) "+
                                                          " or    (? = 'L' and lt1.print_xref1_lic_addr_ind <> 'N'))))) "+
                                                          " order by 6 desc, 7 asc ";
              try
                con = getDSconn();
         //  stmt = con.createStatement();
              pstmt=con.prepareStatement(strQuery);
               // rs = stmt.executeQuery(strQuery);
            pstmt.setString(1,strAddrtype);
             pstmt.setString(2,strEntId);
             pstmt.setString(3,strLicId);
             pstmt.setString(4,strAddrtype);
             pstmt.setString(5,strAddrtype);
             pstmt.setString(6,strEntId);
             pstmt.setString(7,strLicId);
             pstmt.setString(8,strAddrtype);
             pstmt.setString(9,strAddrtype);
             pstmt.setString(10,strAddrtype);
             pstmt.setString(11,strAddrtype);
    pstmt.setString(12,strAddrtype);
    pstmt.setString(13,strAddrtype);
              rs=pstmt.executeQuery();
                while (rs.next())
                  LicenseeForm licenseInfo = new LicenseeForm();
                  licenseInfo.setLicId(rs.getString(1));
                  licenseInfo.setLicNo(rs.getString(2));
                  licenseInfo.setLicType(rs.getString(3));
                  //licenseInfo.setBoard(rs.getString(4));
                  licenseInfo.setRenewStatus(rs.getString(4));
                  alMasterLicList.add(licenseInfo);
                rs.close();
                pstmt.close();
                con.close();
                con = null;
              catch (RuntimeException re)
                    throw re;
              catch(Exception e)
              { e.printStackTrace();
                try
                  rs.close();
                  pstmt.close();
                  con.close();
                  con = null;
                catch(Exception i){}
              finally
                try
                  pstmt.close();
                  con.close();
                  con = null;
                catch(Exception i){}
              return alMasterLicList;     
           

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

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

  • When to use prepared statement in java?

    Hi all,
    If we have query like select * from {tablename} (Here tablename is the variable) then will the use of prepared staement improve the performance? My guess is use of statement in this case is a better option rather than prepared statement as the tablename may change for every other query.I think are not useful if tablename changes.They are useful only when the where clause has dynamic values.

    cantor wrote:
    Are you sure that your approach is possible? The next example causes exception for me.
    PreparedStatement ps = conn.prepareStatement("select * from ?");
    ps.setString(1, "TABLE_NAME");
    ps.executeQuery();
    I didn't say that he should solve it in that way. He should create one prepared statement like this "select a, b, c from tablename1" and another prepared statement when he wants to execute "select d, e, f from tablename2"
    >
    And as I understand, this code will not improve perfomance (and even will not work). As I said it can.
    Prepared statements make possible usage compiled queries inside DB. When DB gets prepared statement call, it need to parse it only once. And it can collect some statistic to improve execution plan. But when table name is not specified, this approach will not work.Yes it might. There are database drivers that can cache prepared statements and it's isn't likely that he executes that query on more than e.g. 20 tables?
    The database can also cache compiled statements in a cache.
    Kaj

  • Using partition in prepared statement

    Hello,
    I am connecting to an oracle 9i database and write a prepared statement like
    String query = "SELECT * FROM ADM.TABLE1 PARTITION (TABLE1_?)";
    PreparedStatement pstmt = dbConnection.prepareStatement(query);
    pstmt.setString(1, "20" + callDate); // Partitions are like TABLE1_20030605
    ResultSet rs = pstmt.executeQuery();
    I get this error ORA-00933: SQL command not properly ended
    Any ideas if i am substituting the value correctly or if this is the right way to use prepared statement ?

    It is the wrong way to use a prepared statement.
    You will need to create the string dynamically.

Maybe you are looking for

  • Can't browse contents of Nokia 7610 on Windows 7

    Hello! I can't access the files on my Nokia through my laptop with Windows 7. On another computer with windows XP it worked allright.  I am using PC suite 7, installed new cable drivers, and updated the phone software.  It synchronizes everything all

  • Oracle.xml.binxml.BinXMLException

    Hi, while retrieving XMLType column from oracle database (11.2.0.2), following error appears in the weblogic 10.3.4 application servers error logs oracle.xml.binxml.BinXMLException      at oracle.xml.binxml.BinXMLTokenManager.registerTokenSetFromMeta

  • Mac indisign cs6, photoshop cs6 havent got installed. Kindly provide some remedies.

    I am using mac mountain lion and recently purchased Adobe design and web premium cs6. I tried the full install but photoshop and indesign cs6 havent got installed. What to do now? however dreamweaver, fireworks, flash, illustrator successfully instal

  • How to see all the customers under one company code?

    hi, I would like to know, is there any standard transaction code to see all the customers under one company code? thanks.

  • ITunes 11.2 doesnt open on my Mac?

    Well I have a very old MacBook, yes the white one. The one with Intel Core 2 Duo and 2 GB of ram. I just updated my iTunes on my Mac via Software Update. Since my version of Mac OS is 10.6.8 When its newly updated. When I open iTunes it just jumps fo