Use Multiple Insert Statements in Prepared Statements

Hi Friends
i am stuck in a problem for which i need your help.i will brief you about the issue below.
I am having Multiple Insert Statements which i need to execute to put the data in the database.i have a doubt about the use of the executeUpdate() function in the statement interface. sample code is as below.
stmt = conn.prepareStatement("INSERT INTO Client ( clientPk, provincePk, countryPk, statusPk, branchPk, salutation, ) VALUES(PID, 2, '123123123', '123', '66', 1, 1 );");
int n =stmt.executeUpdate();
Now the problem is how do i insert multiple Insert statements using the conn.prepareStatement().should i do like
stmt = conn.prepareStatement("")
int n =stmt.executeUpdate();
stmt = conn.prepareStatement("")
int n =stmt.executeUpdate();
stmt = conn.prepareStatement("")
int n =stmt.executeUpdate(); ..................................
should i use the same steps to execute each individual query and then use executeUpdate().
Please let me know the correct procedure to be followed to execute these tasks.waiting for a positive reply from your side.
Thanks & Regards
Vikram K

Hi
Thanks a lot once agin for the reply.
I think i have figured out the solution. I am using SQL statements in the Prepared statements(""). But now i have dropped the idea of using the prepared statement and decided to use the simple Statement instead.
what i have done is as below.
conn = ConnectionFactory.getInstance().getConnection();
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO Client ( clientPk, provincePk, countryPk, statusPk, branchPk, salutation, heightMeasurementType, weightMeasurementType ) VALUES(PID, '1', '1', '0', '1', 'Mr', CONCAT('Jason ', PID), 'R', 'Mawdsley', '123', '66', 1, 1 );");
stmt.executeUpdate("INSERT into Cp () Values ()");
stmt.executeUpdate("INSERT into gp () Values ()");
stmt.executeUpdate("INSERT into jk () Values ()");
I think this makes sense to use the Statement and execute all the queries in one shot rather than using PS.
thanks a lot for your help.
Regards
Vikram K

Similar Messages

  • How can i use multiple row subquery in update statement

    Hai All
    I using group function in my update statement.. and i need to update more rows so i need to use multiple row
    subquery pls tell me how to use multiple row subquery in update statement
    For example
    while i am using this like this i got an error
    update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
    barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
    Pls tell me how to use with example
    Thanks & regards
    Srikkanth.M

    Hai Man
    Thanks for ur response Let me clear what i need
    First step Fetch the records as text file and stores into table T1
    and the next step is i have seperated the text using substring and stores in different columns of a table
    There are two shifts 0815 to 1645 and 1200 and 2000
    Here I rep IN and O rep OUT
    Empno date time inout
    001 01-01-10 0815 I
    002 01-01-10 0815 I
    003 01-01-10 0818 I
    001 01-01-10 1100 0
    001 01-01-10 1130 I
    002 01-01-10 1145 0
    002 01-01-10 1215 I
    004 01-01-10 1200 I
    005 01-01-10 1215 I
    004 01-01-10 1315 O
    004 01-01-10 1345 I
    001 01-01-10 1645 0
    002 01-01-10 1715 0
    003 01-01-10 1718 0
    004 01-01-10 2010 0
    005 01-01-10 2015 0
    This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
    T2 contains like this
    Empno Intime Intrin Introut Outtime Date
    001 0815 1100 1130 1645 01-01-10
    002 0815 1145 1215 1715 01-01-10
    003 0818 1718 01-01-10
    004 1200 1315 1345 2010 01-01-10
    005 1215 2015 01-01-10
    This what i am trying to do man but i have little bit problems Pls give some solution with good example
    And my coding is
    declare
         emp_code varchar2(25);
    in_time varchar2(25);
    out_time varchar2(25);
    Cursor P1 is
    Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    From temp_att
    group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    ORDER BY enpno,pdate,ptime;
    begin
         for r2 in p1 loop
    declare
    bar_code varchar2(25);
    begin
    select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
    For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
    if r2.inout ='O' then
    update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
    end if;
    end loop;     
    exception
         when no_data_found then
         if r2.inout ='I' then
                   insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
         end if;
    end;
    end loop;
    commit;     
         end;
    Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
    and how can i use it in the update statement
    Thanks In Advance
    Srikkanth.M

  • Statement and Prepared Statement

    if i write a same query with statement and preparedStatement
    like
    Select * from emp_detail where emp_id =20;
    stmt= con.createStatment();
    rs = stmt.executeQuery(query);
    and using preparedStatement
    Select * from emp_detail where emp_id =?;
    pstmt= con.prepareStatement();
    pstmt.setInt(1,20);
    rs = stmt.executeQuery(query);
    Using which statment(Statement or Prepared Statement) the data will retrive fast and why.... in these case ????

    Statement should be quicker than Prepared Statement, because
    Statment do only one thing: send that sql to server or run that sql directly.
    Prepared Statement should do two (or more than two)things:
    1. parse your sql first, prepare a store procedure, then call that store procedure.
    Or
    2. prase your sql first, then use your value to replace "?" for getting a new sql, then work like Statement.
    Prepared Statement is quiker when you use it repeatedly.

  • How to retrieve a prepared statement from prepared statement cache?

    Hi All,
    I have created the connection pool during application server startup. The connection pool are getting created successfully. I have also created the prepared statements and stored as part of each connection in the connection pool.
    can anyone please tell me on how do I retrieve a prepared statement from prepared statement cache from a connection object.
    Any pointers to info source will be REALLY appreciated.
    Many Thanks in Advance,
    C R Baradwaj

    Raghuram Bharatwaj C wrote:
    Hi Joe,
    I have created a connection poool in my startup class and created the
    neccessary prepared statements for a each connection. I have 10 prepared
    statements to be created for each connection. I have created all the 10 prepared statements using the loop as mentioned below
    String [] epc_stmts;
    private java.sql.PreparedStatement[] _pstmts;
    if (epc_stmts!= null)
                   _pstmts = new PreparedStatement [len = epc_stmts.length];
                   for (i=0; i<len; i++)
                        _pstmts[i] = db.prepareStatement (epcstmts);
    I have closed the connection after the prepared statements are created.
    Now, How do i access a prepared statement from the connection object.
    Nothing. Are you talking about a WebLogic pool? If so, then therafter,
    whenever your application gets a pool connection, when it calls
    prepareStatement() with the same SQL as you prepared those statements,
    it will get a cached statement. Your array is unnecessary.
    Joe
    >
    Many Thanks in Advance,
    C R Baradwaj

  • Converting simple statements to prepared statements...

    hi all,
    how can i convert this update statement to a prepared statement...?
    // this will append 'newData'
    // to the current value of colName
    UPDATE table
    SET colName = colName + 'newData'
    WHERE colID = 1
    // i tried using this, as the tutorial says that
    // just replace your values with a '?' but it
    // doesn't work... how do i make it work???
    PreparedStatement updateStmt = con.prepareStatement( "UPDATE table
    SET colName = colName + ?
    WHERE colID = ?" );
    updateStmt.setString( 1, "newData" );
    updateStmt.setInt( 2, 1 );
    updateStmt.executeUpdate();
    thanks in advance!

    You should try the following:
    PreparedStatement updateStmt = con.prepareStatement( "UPDATE table SET colName = ? WHERE colID = ?" );
    updateStmt.setString( 1, colName +"newData" );
    updateStmt.setInt( 2, 1 );
    updateStmt.executeUpdate();
    con.commit();
    Your row with colID=1 should be updated, assuming you have the appropriate tablename and column names in the sql.

  • Error using multiple subqueries in a from statement - sorry so long

    From the query below, my results should only be 3 rows but, for whatever reason, I'm getting 3 of each operation number. Can someone PLEASE tell me why this is looking more than once?
    Version - Oracle 9i
    Here's the query
    select base.equivalent_operation_number, ((pip.operation_count/PIPInject.op_inject_count) - (base.operation_count/baseInjecT.Op_inject_count)) as Read_Rate_Difference
    from
    (select T2.EQUIVALENT_OPERATION_NUMBER, count(T2.EQUIVALENT_OPERATION_NUMBER) as operation_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, BASELINE_JK T3
    WHERE
    (T3.IMAGE_NAME=T1.IMAGE_NAME AND LENGTH(T3.POSTNET_CODE) > 1)
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER) base,
    (select T2.EQUIVALENT_OPERATION_NUMBER, count(T2.EQUIVALENT_OPERATION_NUMBER) as operation_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, PIP_JK T3
    WHERE
    (T3.IMAGE_NAME=T1.IMAGE_NAME AND LENGTH(T3.POSTNET_CODE) > 1)
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER)pip,
    (select t2.equivalent_operation_number, count(T2.EQUIVALENT_OPERATION_NUMBER) as op_inject_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, BASELINE_JK T3
    WHERE
    T3.IMAGE_NAME=T1.IMAGE_NAME
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER) BaseInject,
    (select t2.equivalent_operation_number, count(T2.EQUIVALENT_OPERATION_NUMBER) as OP_Inject_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, PIP_JK T3
    WHERE
    T3.IMAGE_NAME=T1.IMAGE_NAME
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER)PIPInject
    where base.equivalent_operation_number = pip.equivalent_operation_number
    AND
    baseinject.op_inject_count = pipinject.op_inject_count;
    Here's the results which should only return 3 rows.
    EQUIVALENT_OPERATION_NUMBER READ_RATE_DIFFERENCE
    0 -.01728723
    0 -.00131154
    0 -.00010203
    894 -.07047872
    894 -.00041597
    894 -.00534705
    895 -.68284574
    895 -.00403019
    895 -.05180589
    9 rows selected.
    Here's the explain plan
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 MERGE JOIN
    2 1 SORT (JOIN)
    3 2 NESTED LOOPS
    4 3 MERGE JOIN
    5 4 SORT (JOIN)
    6 5 VIEW
    7 6 SORT (GROUP BY)
    8 7 NESTED LOOPS
    9 8 NESTED LOOPS
    10 9 TABLE ACCESS (FULL) OF 'PIP_JK'
    11 9 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_
    DATA'
    12 11 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (U
    NIQUE)
    13 8 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATIO
    N_NUMBER_MAPPING'
    14 13 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQU
    E)
    15 4 SORT (JOIN)
    16 15 VIEW
    17 16 SORT (GROUP BY)
    18 17 NESTED LOOPS
    19 18 NESTED LOOPS
    20 19 TABLE ACCESS (FULL) OF 'BASELINE_JK'
    21 19 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_
    DATA'
    22 21 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (U
    NIQUE)
    23 18 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATIO
    N_NUMBER_MAPPING'
    24 23 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQU
    E)
    25 3 VIEW
    26 25 SORT (GROUP BY)
    27 26 NESTED LOOPS
    28 27 NESTED LOOPS
    29 28 TABLE ACCESS (FULL) OF 'PIP_JK'
    30 28 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_DATA
    31 30 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (UNIQU
    E)
    32 27 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATION_NU
    MBER_MAPPING'
    33 32 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQUE)
    34 1 SORT (JOIN)
    35 34 VIEW
    36 35 SORT (GROUP BY)
    37 36 NESTED LOOPS
    38 37 NESTED LOOPS
    39 38 TABLE ACCESS (FULL) OF 'BASELINE_JK'
    40 38 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_DATA'
    41 40 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (UNIQUE)
    42 37 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATION_NUMB
    ER_MAPPING'
    43 42 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQUE)
    Statistics
    0 recursive calls
    0 db block gets
    4432694 consistent gets
    84423 physical reads
    0 redo size
    958 bytes sent via SQL*Net to client
    425 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    8 sorts (memory)
    0 sorts (disk)
    9 rows processed

    Yeah, I can see why it didn't return any rows... here's what I need:
    Is get the difference between counts from two tables where there are two conditions(numerator is one conditon and the denomenator is another condition) based on matching operation numbers.
    Condition #1 table 1
    OpNum Count
    1 1000
    2 500
    3 200
    Condition #2 table 1
    OpNum Count
    1 500
    2 700
    3 150
    Condition #1 table 2
    OpNum Count
    1 500
    2 300
    3 450
    Condition #2 table 2
    OpNum Count
    1 500
    2 300
    3 450
    The formula
    Conditions applied to each operation number in each table
    (table1.conditon#1/table1.condition#2) - (table2.condition#1/table2.condition#2)

  • Statement or Prepared Statement???

    Hi,
    Since the PreparedStatement is a Precompiled Statement , can i use it for normal SQL statements where i need to pass a parameter for a select statement like:-
    Instead of this:-
    "Select name from employee where empId= "+empId
    Shall i use :-
    PreparedStatement ps=con.prepareStatement( "Select name from employee where empId= ?")
    Resultset rs=ps.executeQuery();
    if(rs.next()){
    rs.setString(1,empId);
    ps.executeUpdate();
    Which one is better here?? Where i havn't used PreparedStatement repeated execution of statement here. Pls. do provide a solution...
    Thanks,
    JavaCrazyLover

    why to go for normal Statement interface which operates
    during the runtime and slow??.Statement is not slow (unless you define what you mean by slow). They can be efficient in some situations. However, the difference in execution times using a PreparedStatement even in such cases is not very significant. So, it is advisable to always use PreparedStatement.

  • ? in SQL Queries and not using prepared statements

    Using EclipseLink 1.1.1
    Prepared Statements are disabled
    In our production server something went wrong and one of our Read Queries started erroring. A DatabaseException was thrown and we log the "getQuery.getSQLString()" statement. We found this query in the logs:
    SELECT t1.ID, t1.NAME, t1.DESCRIPTION, t1.EXTREFID, t1.STYLESHEET, t1.DDSVNVERSION, t1.FIRSTNAME, t1.LASTNAME, t1.EMAILADDR, t1.PHONENUMBER, t1.ADDRESS, t1.ADDRESS2, t1.CITY, t1.STATE, t1.POSTALCODE, t1.COUNTRY, t1.ADMINACCTNAME, t1.HASDOCUMENTS, t1.HASTIMEDNOTIFICATIONS, t1.STATUS, t1.ENTRYDATE, t1.EVALEXPDATE, t1.LASTREMINDDATE, t1.FULLUSERS, t1.LIMUSERS, t1.REQUSERS, t1.ISENTERPRISE, t1.EXPDATE, t1.ISDISABLED, t1.DISABLEDDATE, t1.NEEDLICENSEAGREEMENT, t1.ISWARNINGDISABLED, t1.LOCALE, t1.TIMEZONE, t1.CURRENCY, t1.DOMAIN, t1.DOCUMENTSIZE, t1.EXTRADOCUMENTSTORAGE, t1.ONDEMANDOPTIONS, t1.SSOTYPE, t1.RESELLERID, t1.ACCOUNTREPID, t1.LASTUSAGEREPORTDATE, t1.NEXTUSAGEREPORTDATE, t1.USAGEREPORTATTEMPTS FROM T_SSOOPTIONS t0, T_CUSTOMERS t1 WHERE *((((t0.SSOENABLED = ?) AND (t1.SSOTYPE IN (?, ?))) AND (UPPER(t1.DOMAIN) = ?)) AND (t0.CUSTOMERID = t1.ID))*
    Notice the values weren't entered into the where clause. We had to bounce the application to fix the problem. I've never seen this before. I've added more debugging statements to the code - so if this happens again in the future I'll have more information to report on. In the mean time I'm wondering if anyone else has every seen a problem of this nature.

    Database error due to invalid SQL statement.
    I don't have a stack, we were catching the exception and not printing the stack :(
    Like I mentioned in my first post, I added more debugging code (e.printStackTrace()). I understand this is hard to track down without more information. I was just hoping you guys had seen something like this before and had any insight. Like I mentioned before: this is on our production server. I've never seen this type of error before. That particular server (we run in a cluster mode) had been up for several days and then started generating that error. IT bounced the node and everything went back to normal. We have been using toplink for about 5 years now and have never seen this problem, until August 3rd 2009. The only thing that has changed recently is our migration from toplink 10 to EclipseLink. I was wondering if anyone knows if anything had changed in EclipseLink/toplink 11 with the generation of SQL queries.
    I'll keep looking. There is more debugging code in there now. Since the error was "Database error due to invalid SQL statement" this implies the SQL was generated, exited that part of the code and was sent to the db where it failed. I'm afraid the printStackTrace won't help if this error happens again.

  • Prepared statements related problem

    Hi,
    i have this strange problem with prepared statements i think.
    When i execute an insert query without prepared statements i works fine (always), when i use prepared statements it sometimes gives a db error saying i'm trying to insert a null value.
    The problem is that I'm not!!!
    If i were why does it work sometimes?
    It may be a bug but i don't know where to look for it... is it a prepared statements, application server or db2 problem?

    This is the code...
         public void insertArticolo(Articolo item) throws Exception {
              PreparedStatement ps = null;
                   try {          
                        StringBuffer sql = new StringBuffer("insert into RUW.RUWT1_ARTICOLO (");
                        sql.append("C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, ");
                        sql.append("C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,");
                        sql.append("C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO");
                        sql.append(") values (");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?");
                        sql.append(")");
                        ps = connectionCreatePreparedStatement(sql.toString());
                        System.out.println(sql.toString());
                        KeyArticolo keyArticolo = item.getKeyArticolo();
                        KeyPartita keyPartita = keyArticolo.getKeyPartita();
                        Ente ente = keyPartita.getKeyRuolo().getEnte();
                        System.out.println("/"+ ente.getCodEnte()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getConcessione().getCodConc()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getAnnoRuolo()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getProgRuolo()+ "/");
                        System.out.println("/"+ keyPartita.getNumPartita()+ "/");
                        System.out.println("/"+ keyPartita.getProgPartita()+ "/");
                        System.out.println("/"+ item.getKeyArticolo().getProgArticolo()+ "/");
                        System.out.println("/"+ item.getCodEntrata()+ "/");
                        System.out.println("/"+ ente.getTipoUfficio()+ "/");
                        System.out.println("/"+ ente.getCodUfficio()+ "/");
                        System.out.println("/"+ item.getTipoImposta()+ "/");
                        System.out.println("/"+ item.getAnnoImposta()+ "/");
                        System.out.println("/"+ item.getCaricoOrigine()+ "/");
                        if (item.getDescArticolo().equals("")) {
                             item.setDescArticolo(" ");
                        System.out.println("/"+ item.getDescArticolo()+ "/");
                        ps.setLong(1,ente.getCodEnte());
                        ps.setLong(2,keyPartita.getKeyRuolo().getConcessione().getCodConc());
                        ps.setLong(3,keyPartita.getKeyRuolo().getAnnoRuolo());
                        ps.setLong(4,keyPartita.getKeyRuolo().getProgRuolo());
                        ps.setLong(5,keyPartita.getNumPartita());
                        ps.setLong(6,keyPartita.getProgPartita());
                        ps.setLong(7,item.getKeyArticolo().getProgArticolo());
                        ps.setString(8,item.getCodEntrata());
                        ps.setString(9,ente.getTipoUfficio());
                        ps.setString(10,ente.getCodUfficio());
                        ps.setString(11,item.getTipoImposta());
                        ps.setLong(12,item.getAnnoImposta());
                        ps.setLong(13,item.getCaricoOrigine());
                        ps.setString(14,item.getDescArticolo());
                        ps.executeUpdate();
                   catch (Exception e) {
                        e.printStackTrace();
                        connectionCloseStatement(ps);
                        throw e;
              }and this is the result of the systemout
    [10/03/06 14.07.07:051 CET] 76357635 SystemOut O insert into RUW.RUWT1_ARTICOLO (C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    /13199/
    /66/
    /2002/
    /1564/
    /28330/
    /1/
    /2/
    /0997/
    /120/
    /2002/
    /11900/
    / /

  • Prepared Statement with IN Operator

    Hello all, do anyone know how to use IN operator in a prepared statement? For ex.,
    "select name from user where user_no in (?)"
    If I do preparedStatement.setString(1, "2, 3, 4") and execute it, it would give me an ORA-01722: invalid number exception. Any help or pointer will be appreciated. Thanks.
    yien

    You can't (easily) pass a comma-separated list to a SQL statement. If you want to pass N values straight to a PreparedStatement, you would need N bind variables, i.e.
    select name from user where user_no in (?, ?, ?)I would tend to either pass an array to a stored procedure that returned a REF CURSOR for the SELECT or create a pipelined table function that parsed the comma-separated list into a table structure.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Pooling Prepared Statement and Resultset

    Is their any mechanism in Weblogic by which we can pool prepared statements and
    resultset.

    Yes you can cache prepared statements. The connection pool will
    automatically cache the prepared statements (10 prepared statement was the
    limit in previous so you may want to write some startup class to load the
    imp prepared statements.). When you reuse the prepared statement the
    connection pool will pick it from its prepared statement cache. In 6.1 you
    can configure the number of prepared statements that you want to cache.
    But you cannot have multiple resultsets open for the same statement object.
    You can have cache rows though.
    Please search the bea newsgroups for more info. There are a bunch of posts
    that will be helpful to you.
    http://search.bea.com/weblogic/gonews/
    sree
    "hogan" <[email protected]> wrote in message
    news:3bd9cf88$[email protected]..
    >
    Is their any mechanism in Weblogic by which we can pool preparedstatements and
    resultset.

  • How: multiple insert stmt's in Database Express edition SQL commands GUI?

    I have installed the Express 10g version today and played around with it for a while.
    If I go to the SQL commands GUI and enter one insert like this:
    INSERT INTO pageit (PagID, PagParent, PagName, PagActive) VALUES (19, 17, 'Mango tree', 1)
    then it works nicely:
    But if I do this:
    INSERT INTO pageit (PagID, PagParent, PagName, PagActive) VALUES (20, 17, 'Grape trees', 1);
    INSERT INTO pageit (PagID, PagParent, PagName, PagActive) VALUES (21, 16, 'Animals', 1);
    Then it says:
    ORA-00911: invalid character
    Looks like semicolon is not allowed,
    but if I remove the semicolon then it says;
    ORA-00905: missing keyword
    Is there a way to use multiple insert statements in one go in this GUI at all?
    If not, could someone please recommend how I do this.
    I have exported thousands of insert lines from MySql and I would like to get them into my newly created Oracle table without having to type one line at the time in this gui.
    Any suggestions?
    Then if there is a nice WEB GUI like phpmyadmin for Oracle then I would like to know about that to? (Preferably free)

    I've not done a lot with the express edition, so there may be tools I'm not aware of. There is a dedicated Express Edition forum that may be more helpful for some of these questions.
    I would normally use the command-line SQL*Plus to run a script with a large number of SQL statements. I'd generally prefer, though, to get a comma-separated data file from the other system and load that into Oracle using SQL*Loader for efficiency reasons.
    In Oracle, you would normally only want a single database on a single physical machine. I know in SQL Server that what they call a "database" is roughly equivalent to a "schema" in Oracle, which is created by creating a new user.
    Justin

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

  • How to Insert Character using Prepared statement

    Hi All,
    Can anyone let me know how can I insert character using prepared statement.
    Thanks
    Sameer

    In the future JDBC related questions should be posted into the JDBC forum.
    Can you please provide some more information about what you are trying to do? It isn't clear to me. Are you trying to update a CHAR field?

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

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

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

Maybe you are looking for