Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:48:19+00:00 2026-06-05T06:48:19+00:00

I want to execute the multiple queries or job in one execute. Something like

  • 0

I want to execute the multiple queries or job in one execute.
Something like this
eg:

String query = """
        SELECT * FROM tab1;
        INSERT INTO tab1 VALUES( … );
        UPDATE tab1 … ;
        DELETE FROM tab1 … ;
        """ ; 
Statement st = con1.createStatement();
ResultSet rs = st.executeQuery(query); 

Or multiple SELECT queries. Queries will be dynamic.

But I am not able to do this. What is the way to run multiple queries separated by semicolon?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:48:20+00:00Added an answer on June 5, 2026 at 6:48 am

    you can achieve that using following example uses addBatch & executeBatch commands to execute multiple SQL commands simultaneously.

    Batch processing allows you to group related SQL statements into a batch and submit them with one call to the database. reference

    When you send several SQL statements to the database at once, you reduce the amount of communication overhead, thereby improving performance.

    • JDBC drivers are not required to support this feature. You should use the DatabaseMetaData.supportsBatchUpdates() method to determine if the target database supports batch update processing. The method returns true if your JDBC driver supports this feature.
    • The addBatch() method of Statement, PreparedStatement, and CallableStatement is used to add individual statements to the batch. The executeBatch() is used to start the execution of all the statements grouped together.
    • The executeBatch() returns an array of integers, and each element of the array represents the update count for the respective update statement.
    • Just as you can add statements to a batch for processing, you can remove them with the clearBatch() method. This method removes all the statements you added with the addBatch() method. However, you cannot selectively choose which statement to remove.

    EXAMPLE:

    import java.sql.*;
    
    public class jdbcConn {
       public static void main(String[] args) throws Exception{
          Class.forName("org.apache.derby.jdbc.ClientDriver");
          Connection con = DriverManager.getConnection
          ("jdbc:derby://localhost:1527/testDb","name","pass");
    
          Statement stmt = con.createStatement
          (ResultSet.TYPE_SCROLL_SENSITIVE,
          ResultSet.CONCUR_UPDATABLE);
          String insertEmp1 = "insert into emp values
          (10,'jay','trainee')";
          String insertEmp2 = "insert into emp values
          (11,'jayes','trainee')";
          String insertEmp3 = "insert into emp values
          (12,'shail','trainee')";
          con.setAutoCommit(false);
          stmt.addBatch(insertEmp1);//inserting Query in stmt
          stmt.addBatch(insertEmp2);
          stmt.addBatch(insertEmp3);
          ResultSet rs = stmt.executeQuery("select * from emp");
          rs.last();
          System.out.println("rows before batch execution= "
          + rs.getRow());
          stmt.executeBatch();
          con.commit();
          System.out.println("Batch executed");
          rs = stmt.executeQuery("select * from emp");
          rs.last();
          System.out.println("rows after batch execution= "
          + rs.getRow());
       }
    } 
    

    refer http://www.tutorialspoint.com/javaexamples/jdbc_executebatch.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute a query like this var result = from entry in
I want to execute multiple, separate SQL statements like in the JDBC cookbook: Statement
I want to submit (execute) values from multiple forms, not just the enclosing form.
I want to execute a single Query (or Stored Proc with multiple resultsets). I
I want to execute multiple queries asynchronously. Now for that I have searched but
I want to execute multiple statements from my data access layer using C# dan
I want to execute this script (view source) that uses Google Translate AJAX API
I want to execute a batch file from a java program. I am using
i want to execute the query in master database it self IF OBJECT_ID(N'DB1.dbo.T_table1', N'U')
It looks like #temptables created using dynamic SQL via the EXECUTE string method have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.