Batching disparate JDBC statements

I am trying to batch execute a bunch of JDBC statements which are disparate - ie. insert , update. Is there a way to do this via Oracle's Thin JDBC driver? Someone mentioned that it might be possible using Oracle JDBC Callable statement interface to bunch together a bunch of SQL statements(not stored procedures) - but i could not find any information on this.
Thanks

Seems like you are making it harder than it needs to be. What is wrong with JDBC batching or even Oracle Style batching?
PreparedStatement psIns = con.prepareStatement( <some insert statement> );
PreparedStatemetn psUpd = con.prepareStatement( <some update statement> );
for ( int at = 0; at < numRecsToInserAndUpdate; ++at )
    psIns.setLong( 1, uids[at] );
    psIns.setBlah( 2, ... );
    psIns.addBatch();
    psUpd.setString( 1, updateStrings[at] );
    psUpd.addBatch();
psIns.executeBatch();
psUpd.executeBatch();The above example uses JDBC style batching, you can as easily do this with Oracle style batching.
R.

Similar Messages

  • What is a better approach, batch or prepared statement?

    Hi,
    In my application, the user account property will be retrieved from DB and the last login time will be updated after a successful sign on. There are two query statements in this procedure; select and update. What is a better approach in JDBC to deal with the two queries: batch or prepared statement?
    Thanks.

    Hi, Duffy,
    Thanks for your input.
    I would like to use PreparedStatement with batch update. From my reading, however, it is not suitable to use PreparedStatement with batch update. At less, I haven't see a single example on the tutorial or article sections of this site. I am not sure the following is valid or not:
                   stmt = connection.prepareStatement(INSERT_SMT_QUERY_STR);
                   stmt.setLong(1, details.getRegardID());
                   stmt.setLong(2, details.getWriterID());
                   stmt.setInt(3, details.getVisibility());
                   stmt.setString(4, details.getSubject().trim());
                   stmt.setString(5, details.getContent().trim());
    stmt.addBatch() <-- what goes into here?

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

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

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

  • How to get the jdbc statement profile in 8.1

    the wls 8.1 api does not have the methods in the wls 7 api for jdbc statement profiling...
    in 7, the connection pool mbean has
    setSqlStmtProfilingEnabled()
    and the connection pool runtime mbean has
    getStatementProfiles(int index, int count)
    but in 8, i don't see these. i see the JDBCStatementProfile object in the api, but i don't see how to enable it or retrieve it.
    is this feature removed? or moved?
    thanks

    Thanks for your response. But I need Process ID
    not Product ID.
    GetCurrentProcessID
    Function should return you Process ID.
    Gaurav Khanna | Microsoft .NET MVP | Microsoft Community Contributor

  • JDBC Statement Profiling

    Hi,
    I have turned on JDBC Statement Profiling on my server. I can
    get the statements being executed, but the Start & Stop times or
    all Statements is the same. The relevant code and output follows.
    Anybody see what I am doing wrong.
    thanks,
    Harish.
    public static void printJDBCStatement(JDBCStatementProfile mb) {
    System.out.println("\tStatement: " + mb.getStatementText());
    System.out.println("\t\ttime = " + mb.getTimeTaken());
    System.out.println("\t\tstarttime = " + mb.getStartTime());
    System.out.println("\t\tendtime = " + mb.getStopTime());
    System.out.println("\t\tthread = " + mb.getThreadId());
    System.out.println("\t\tParams:");
    int cnt = mb.getParameterCount();
    for(int i=0; i<cnt;i++) {
    System.out.println("\t\t\tParam " + (i+1) + mb.getParameter(i+1));
         Statements:
         Statement: INSERT INTO QUERY (ID, TYPE, OWNER, OBJVERSION) VALUES (?, ?, ?,
    0)
              time = 0
              starttime = 1033591935157
              endtime = 1033591935157
              thread = Thread-15
              Params:
                   Param 132397
                   Param 212650
                   Param 399999999
         Statement: SELECT OBJVERSION FROM QUERY WHERE ID = ? FOR UPDATE NOWAIT
              time = 0
              starttime = 1033591935167
              endtime = 1033591935167
              thread = Thread-15
              Params:
                   Param 132397
         Statement: DELETE FROM SELECT_LIST WHERE QUERY_ID = ?
              time = 0
              starttime = 1033591935177
              endtime = 1033591935177
              thread = Thread-15
              Params:
                   Param 132397
         Statement: SELECT 5, OBJVERSION, 0 FROM QUERY WHERE ID = ?
              time = 0
              starttime = 1033591935187
              endtime = 1033591935187
              thread = Thread-15
              Params:
                   Param 132397

    "Harish" <[email protected]> wrote in message
    news:[email protected]..
    >
    I know for a fact that the statements take more than a 1ms.Could you try to run this code and tell what it prints?
    public class test {
    public static void main(String args[]) throws Throwable {
    long previousTime = 0;
    long currentTime = 0;
    for (int i = 1; i < 1000000; i++) {
    previousTime = System.currentTimeMillis();
    // Thread.sleep(20);
    currentTime = System.currentTimeMillis();
    if (currentTime != previousTime) {
    System.out.println("Difference: " + (currentTime - previousTime));
    Regards,
    SlavaImeshev
    >
    thanks,
    Harish.
    "Slava Imeshev" <[email protected]> wrote:
    Hi Harish,
    AFAIR this fact means that execution time is
    less than 1ms. It's because java timer is not
    very good at measuring precise periods of time.
    So these digits are pretty good :)
    Regards,
    Slava Imeshev
    "Harish" <[email protected]> wrote in message
    news:3d9b6cfd$[email protected]..
    Hi,
    I have turned on JDBC Statement Profiling on my server. I can
    get the statements being executed, but the Start & Stop times or
    all Statements is the same. The relevant code and output follows.
    Anybody see what I am doing wrong.
    thanks,
    Harish.
    public static void printJDBCStatement(JDBCStatementProfile mb){>
    Statements:
    Statement: INSERT INTO QUERY (ID, TYPE, OWNER, OBJVERSION) VALUES
    0)
    time = 0
    starttime = 1033591935157
    endtime = 1033591935157
    thread = Thread-15
    Params:
    Param 132397
    Param 212650
    Param 399999999
    Statement: SELECT OBJVERSION FROM QUERY WHERE ID = ? FOR UPDATE NOWAIT
    time = 0
    starttime = 1033591935167
    endtime = 1033591935167
    thread = Thread-15
    Params:
    Param 132397
    Statement: DELETE FROM SELECT_LIST WHERE QUERY_ID = ?
    time = 0
    starttime = 1033591935177
    endtime = 1033591935177
    thread = Thread-15
    Params:
    Param 132397
    Statement: SELECT 5, OBJVERSION, 0 FROM QUERY WHERE ID = ?
    time = 0
    starttime = 1033591935187
    endtime = 1033591935187
    thread = Thread-15
    Params:
    Param 132397

  • What is the size limitation of Oracle JDBC Statement?

    Want to know how large is the limiation of one complete SQL insert string can be place
    into a JDBC Statement and can insert the big record successfully. I tried up to 13K, JDBC still can accept it. Does some experienced
    guru can tell me what is the size limitation
    for insert or update SQL string JDBC can accept it?
    Thanks a lot.

    None known. More than 10 GB. Please note Acrobat is not for server use (I mention that because you mention C# and experience shows it is often preferred for backend development).

  • Jdbc statement in case of an unknown database operation

    hi,
    in an application in java, which makes connection to the database using JDBC,
    if for eg, i am not sure if the statement is going to be a select or update or insert, which method of Statement i should be using. ?
    Thanx.

    try execute() method of java.sql.Statement object.
    hi,
    in an application in java, which makes connection to the database using JDBC,
    if for eg, i am not sure if the statement is going to be a select or update or insert, which method of Statement i should be using. ?
    Thanx.

  • Bank statement is not creating  Batch in upload statement in FF67.

    Dear Guru,
      We have company code in country india and china.
    When uploading bank statement by T. code FF67, batch is not creating for company code under china,but creating batch for india company code.
    Variant is taken  same for all company code and process type -2  is selected (tested also in 3).
    Please advice us. Full Point will be rewarded .
    Regards,
    Nrusingha

    Hello,
    Your transaction types (external provided by the bank) are being linked to an interpretation algorithm, which requires a reference field.
    Can you please check the following:
    IMG: Financial Accounting ==> Bank Accounting ==> Business Transactions ==> Payment Transactions ==> Manual Bank Statement ==> Electronic Bank Statement Make Global Settings for Electronic Bank Statement
    Give your chart of accounts
    Select Create Transaction Type
    Click on Assign External Transaction Types to Posting Rules
    See your External Transaction Type (if it is a debit use - and credit use +)
    Check your posting rule
    See the interpretation algorithm: Use 1 (Standard Algorithm)
    Planning Type, Transaction (Keep it blank)
    Processing Type: 5 Bank Transfer BACS/bk collection BACS/customer cash inflow
    Only in case of outgoing check (cheque), use interpretation algorithm 13 and Processing Type 1 (Clering with check)
    If you correct the entries like this, hopefully you will get rid of this warning.
    Thanks,
    Ravi

  • JDBC Statement Bug with OracleLite 4.0.1.2?

    I have found what appears to be a bug. Has anyone else encountered this bug. I have the following code:
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select columnA,columnB from tableA");
    while (rs.next())
    System.out.println("ColumnA="+rs.getString("ColumnA"));
    System.out.println("ColumnB="+rs.getString("ColumnB"));
    rs.close();
    rs = stmt.executeQuery("select column1, column2,column3 from Table1");
    while (rs.next())
    System.out.println("Column1="+rs.getString("Column1"));
    System.out.println("Column2="+rs.getString("Column2"));
    ("Column3="+rs.getString("Column3"));
    Column 3 is the problem. I get the
    following Exception:
    System.out.printlnjava.sql.SQLException: >>> [ODBC S1002] invalid column number
    After researching it I found that you
    cannot reuse a Statement object over and
    over again. The reason is that the first
    execution of a statement initializes the
    number of columns to be returned and each
    subsequent statement executed does not
    reinitialize the column count. So in the
    case above the column count is 2, and I
    issue a query with 3 columns using the
    same statement object, hence the bug.
    I know the work around, just wanted to
    know if this is a know bug.Any thoughts.
    Mike H.

    I've never heard of anything like this either. But I'm not sure I'm properly tracking what you say. You drop a PR file into the source well and it disappears? If you have a Finder window open and you drag it to the Batch window, you actually see the file deleted in the Finder window?
    Or do you mean that the PR file doesn't get copied to the well?
    Russ

  • WHAT'S GOING ON!!!? JDBC Statement Problems

    Sorry about the 2 previous posts, I kept getting an error when I tried to submit my thread saying that it could not be posted, but obviously it could!!
    Anyway can anyone help me? One of my JSP's refuses to execute properly so I presume there is something wrong with the associated methods in my connector.java file. Everytime I try and run my JSP in TomCat it produces the error message "java.sql.SQLException: java.sql.SQLException: General error, message from server: "Table 'talboothdb.roomsoccupied' doesn't exist". The MySQL statements I am using work fine when typed directly into MySQL via the Command Prompt so I know they arn't the problem. Can anyone see where I am going wrong?
    The neccessary connector java and the JSP I am using are displayed below,
    package javaclass;
    import java.sql.*;
    import java.util.*;
    public class connector{
      String error;
      Connection con;
      ResultSet rs = null;
      int success;
      public connector()   { }
      public void connect() throws ClassNotFoundException,
                               SQLException,
                               Exception {
           try
                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
                con = DriverManager.getConnection(
                     "jdbc:mysql://localhost:3306/talboothdb","","");
                } catch (ClassNotFoundException cnfe) {
                     error = "ClassNotFoundException: could not locate DB driver";
                     throw new ClassNotFoundException(error);
                } catch (SQLException cnfe) {
                     error = "SQL Exception: Could not connect to database.";
                     throw new SQLException(error);
                } catch (Exception e) {
                     error = "Exception: An unknown error occured while connecting to DB";
                     throw new Exception(error);
           public void disconnect() throws SQLException {
                try {
                     if ( con != null ) {
                          con.close();
                } catch (SQLException sqle) {
                     error = ("SQLException: unable to close the DB connection");
                     throw new SQLException(error);
    public void roomsBooked(String arrivalDate, String departureDate)
                                  throws SQLException, Exception {
                if (con != null) {
                  try {
                    PreparedStatement checkBookings;
                    checkBookings = con.prepareStatement
                         ( "CREATE TEMPORARY TABLE roomsoccupied "
                        + "SELECT roombooked.room_id FROM roombooked, booking "
                        + "WHERE "
                        + "roombooked.booking_id = booking.booking_id "
                        + "AND "
                        + "booking.arrival_date <  '?' "
                        + "AND "
                        + "booking.departure_date >  '?' "
                    checkBookings.setString(1, departureDate);
                    checkBookings.setString(2, arrivalDate);
                    checkBookings.executeUpdate();
                  } catch (SQLException sqle) {
                    error = ""+sqle;
                    throw new SQLException(error);
                } else {
                  error = "Exception: Connection to database was lost.";
                  throw new Exception(error);
         public ResultSet roomsAvailable()
                                  throws SQLException, Exception {
                if (con != null) {
                  try {
                    PreparedStatement checkAvailability;
                    checkAvailability = con.prepareStatement
                         ( "SELECT rooms.room_no FROM rooms "
                        + "LEFT JOIN roomsoccupied ON rooms.room_no=roomsoccupied.room_id "
                        + "WHERE roomsoccupied.room_id IS NULL;"
                    checkAvailability.executeQuery();
                  } catch (SQLException sqle) {
                    error = ""+sqle;
                    throw new SQLException(error);
                } else {
                  error = "Exception: Connection to database was lost.";
                  throw new Exception(error);
             return rs;
    <%@ page language="java"
        import="java.sql.*, java.io.*, java.util.*
         " errorPage="error.jsp" %>
    <jsp:useBean id="javaBean" class="javaclass.connector" />
    <html>
    <head></head>
    <body>
    <%
          javaBean.connect();
          String arrivalDate =  request.getParameter("ArrivalDate");
          String departureDate =  request.getParameter("DepartureDate");
          ResultSet rs = javaBean.roomsAvailable();
          while(rs.next())
          {  %> Room number <%= rs.getString(1) %>
           <P><% }
          javaBean.disconnect();
    %>
    </body>
    </html>

    Cross-posted every which way from Sunday:
    http://forum.java.sun.com/thread.jsp?thread=498755&forum=48&message=2355311
    http://forum.java.sun.com/thread.jsp?thread=498751&forum=54&message=2355294
    http://forum.java.sun.com/thread.jsp?thread=498747&forum=48&message=2355272
    http://forum.java.sun.com/thread.jsp?thread=498746&forum=48&message=2355270
    http://forum.java.sun.com/thread.jsp?thread=497689&forum=54&message=2350463
    bluey_the_punch, why are you so wedded to this CREATE TEMPORARY TABLE? In an earlier thread it was recommended that you see if this can be managed with a JOIN. Did you at least try it?
    I see you added PreparedStatement, but you didn't implement it correctly. You certainly don't need to put single quotes around the question marks in the SQL. I'd also recommend that you make those columns dates in your database and use setDate() to bind the values. Strings compare much differently than dates do. If you're not getting the expected results, that might be why.
    It just looks like you've blown off the advice you've gotten so far and just keep asking the same question in hope of getting the answer you want to hear. JMO - MOD

  • Batch updates -- JDBC

    Does any body when I do a batch update, how to track if a particular insert statement has failed in that batch...
    I know that batchUpdate retruns an int[] updatecount.. but, does it tell me which row was not inserted...
    Please help

    I have problem with executeBatch() too. I tried to simulate one error out of other 99 correct data rows by inserting a string into a date field, suppose I should get updateCounts result -3, but I got SQLException and all these 100 rows were not been inserted into database.
    Any idea? Thanx.

  • Logging JDBC Statements in Weblogic 8.1

    Hi,
    I am using Weblogic 8.1.I want to see the JDBC logs and right now I am getting
    "Oracle Jdbc tracing is not avaliable in a non-debug zip/jar file" error. Can
    any one help me with how to turn the JDBC Logging on? I am facing a wierd situation
    that one of my queries(it's from a Message Driven Bean) updates the Oracle database
    with junk values every time(the junk value differs each time) and so I want to
    see the exact SQL query which does this update.
    Thanks
    Jay

    Jay Balasubramanian wrote:
    Hi,
    I am using Weblogic 8.1.I want to see the JDBC logs and right now I am getting
    "Oracle Jdbc tracing is not avaliable in a non-debug zip/jar file" error. Can
    any one help me with how to turn the JDBC Logging on? I am facing a wierd situation
    that one of my queries(it's from a Message Driven Bean) updates the Oracle database
    with junk values every time(the junk value differs each time) and so I want to
    see the exact SQL query which does this update.
    Thanks
    JayHi. When we turn on jdbc logging, oracle's thin driver prints this out. There
    are two separate versions of the thin driver. We ship the regular one. The
    other one is a debug version. The best course is to download oracle's
    latest appropriate thin driver and put the debug version ahead of all weblogic
    jars in the classpath constructed for the server. Then when you turn on jdbc
    logging, you will get copious debug output.
    Joe

  • Rollback of JDBC Statement on error - Stored Procedure

    Hi All,
    We are using the JBDC receiver adapter for inserting the record and for that we are using the Strored Procedure and we have N number of the records for insertion in a single mapping so, we have given the occurence of the Statement 1 : unbounded as, multiple statement will be executed so, my query is if one of statement fails because of some error(Mapping error or data error) what will happen to the statement which are already executed, do they rollback? or it is not possible in case of stored procedure?
    Regards,
    Gaurav

    Hi,
    This is one of the solution but i guess there is one more issue, if we have 10 statements and third statement shows error and Stored Exception exception branch is able to catch then it will rollback the previous statement but can we able to restrict another 7 pending statement for execution or not?
    Regards,
    Gaurav

  • Jdbc Statement hangs

    Folks ,
    I have writen some jdbc code and my applications hangs intermittently, we are using oracle database .
    Thanks,
    Manish

    Hi,
    What do you mean by "applications hangs intermittently"?
    But try to put following logic to figure out what is the time taken by jdbc sql query.
    a) get system time before the execution of sql query and store it in temp variable t1
    b) get system time after the execution of sql query and store it in temp variable t2
    c) Find out the difference and print it
    Once you are confident that SQL query is the one taking longer than expected time, check with Oracle experts in your org. for analyzing the log for the query and reasons for taking so much time
    regards,
    ganga

  • Batch executing SQL Statements stored in a file in SAP DB

    hi,
    I am using SAP DB as database in my j2ee application. As a part of the application purpose, i need to insert a large no. of records in to the database directly. I have created the SQL file which contains the insert statements for the records
    Now i need to execute this file sothat the insert statement which are inside the file get executed. I am using SQL Studio to access to the Database.
    I would like to know whether any options are available in SQL Studio to for executing a SQL File.
    Kindly help
    Best regards,
    Sudheesh...

    Hi,
    I believe that the solution to your problem lies in creating sql studio objects.Please refer to the link below.Select the link "sql dialog" on the page.
    The following options are available for sql dialog.
    The following options are available in the SQL dialog:
    ·        Creating and executing SQL statements
    ·        Setting parameters for SQL statements
    ·        Importing and exporting SQL statements
    Select the "Importing and exporting sql statements" link on this page to know more about it.This will tell you how to import sql statements from ascii files.
    Basically,what you need to do is From the context menu for the SQL dialog, choose Import File or Export File.
    The link I have provided,gives a lot of other information as well.
    http://help.sap.com/saphelp_nw04s/helpdata/en/ee/1c5bdfeba711d4aa2800a0c9430730/frameset.htm
    Hope this helps.
    Regards,
    Harish
    (Please award points for helpful answers)
    Message was edited by: HARISH SUBRAMANIAN

Maybe you are looking for

  • Super drive no longer likes my discs

    whether I insert a music cd or dvd, my super drive growls 3 times then spits out the disc. Any ideas? Need more info? Thanks.

  • How do I save IRS pdf forms so that I can fill in and save the data

    when I downlaod a US government IRS form I am unable to fill in the form, save the data and print, I have tried saving as a pdf from the print menu and using the tools menu none of which works

  • Count for distinct values ...

    Dear Team, I have following situation at hand... COLUMN1      COLUMN2      COLUMN3      TECH111      A11111      MATERAL1   TECH111      A11112      MATERAL2 TECH111      A11112      MATERAL3 TECH111      A11113      MATERAL4 TECH111      A11113     

  • How to I add a background image in an Encore slidehsow?

    How do I add a background image in an Encore slidehsow? Currently the slideshow has a black background and I would love to be able to change that to an image.

  • Facetime - This link needs to be opened with an application

    I am trying to get Facetime on my MacBook Core2 Duo running 10.6.8.  When I go to the Mac App store and click on FaceTime it says "This link needs to opened with an application".  What application and how do I get it on my machine?