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

  • SEARCH
  • Home
  • 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 8002439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:22:05+00:00 2026-06-04T16:22:05+00:00

Hi I was wondering if it is possible to execute something like this using

  • 0

Hi I was wondering if it is possible to execute something like this using JDBC as it currently provides an exception even though it is possible in the MySQL query browser.

"SELECT FROM * TABLE;INSERT INTO TABLE;"

While I do realize that it is possible with having the SQL query string being split and the statement executed twice but I was wondering if there is a one time approach for this.

    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "databaseinjection";
    String driver = "com.mysql.jdbc.Driver";
    String sqlUsername = "root"; 
    String sqlPassword = "abc";

    Class.forName(driver).newInstance();

    connection = DriverManager.getConnection(url+dbName, sqlUsername, sqlPassword);
  • 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-04T16:22:06+00:00Added an answer on June 4, 2026 at 4:22 pm

    I was wondering if it is possible to execute something like this using JDBC.

    "SELECT * FROM TABLE;INSERT INTO TABLE;"
    

    Yes it is possible. There are two ways, as far as I know. They are

    1. By setting database connection property to allow multiple queries,
      separated by a semi-colon by default.
    2. By calling a stored procedure that returns cursors implicit.

    Following examples demonstrate the above two possibilities.

    Example 1: ( To allow multiple queries ):

    While sending a connection request, you need to append a connection property allowMultiQueries=true to the database url. This is additional connection property to those if already exists some, like autoReConnect=true, etc.. Acceptable values for allowMultiQueries property are true, false, yes, and no. Any other value is rejected at runtime with an SQLException.

    String dbUrl = "jdbc:mysql:///test?allowMultiQueries=true";  
    

    Unless such instruction is passed, an SQLException is thrown.

    You have to use execute( String sql ) or its other variants to fetch results of the query execution.

    boolean hasMoreResultSets = stmt.execute( multiQuerySqlString );
    

    To iterate through and process results you require following steps:

    READING_QUERY_RESULTS: // label  
        while ( hasMoreResultSets || stmt.getUpdateCount() != -1 ) {  
            if ( hasMoreResultSets ) {  
                Resultset rs = stmt.getResultSet();
                // handle your rs here
            } // if has rs
            else { // if ddl/dml/...
                int queryResult = stmt.getUpdateCount();  
                if ( queryResult == -1 ) { // no more queries processed  
                    break READING_QUERY_RESULTS;  
                } // no more queries processed  
                // handle success, failure, generated keys, etc here
            } // if ddl/dml/...
    
            // check to continue in the loop  
            hasMoreResultSets = stmt.getMoreResults();  
        } // while results
    

    Example 2: Steps to follow:

    1. Create a procedure with one or more select, and DML queries.
    2. Call it from java using CallableStatement.
    3. You can capture multiple ResultSets executed in procedure.
      DML results can’t be captured but can issue another select
      to find how the rows are affected in the table.

    Sample table and procedure:

    mysql> create table tbl_mq( i int not null auto_increment, name varchar(10), primary key (i) );
    Query OK, 0 rows affected (0.16 sec)
    
    mysql> delimiter //
    mysql> create procedure multi_query()
        -> begin
        ->  select count(*) as name_count from tbl_mq;
        ->  insert into tbl_mq( names ) values ( 'ravi' );
        ->  select last_insert_id();
        ->  select * from tbl_mq;
        -> end;
        -> //
    Query OK, 0 rows affected (0.02 sec)
    mysql> delimiter ;
    mysql> call multi_query();
    +------------+
    | name_count |
    +------------+
    |          0 |
    +------------+
    1 row in set (0.00 sec)
    
    +------------------+
    | last_insert_id() |
    +------------------+
    |                3 |
    +------------------+
    1 row in set (0.00 sec)
    
    +---+------+
    | i | name |
    +---+------+
    | 1 | ravi |
    +---+------+
    1 row in set (0.00 sec)
    
    Query OK, 0 rows affected (0.00 sec)
    

    Call Procedure from Java:

    CallableStatement cstmt = con.prepareCall( "call multi_query()" );  
    boolean hasMoreResultSets = cstmt.execute();  
    READING_QUERY_RESULTS:  
        while ( hasMoreResultSets ) {  
            Resultset rs = stmt.getResultSet();
            // handle your rs here
        } // while has more rs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that looks something like this: select xmlelement(rootNode, (case when XH.ID
I'm currently doing something like this in the AsyncTask's onPostExecute method, where NewTask is
i am wondering is that possible (best practice) to run two long running query
I was wondering if it is possible in a mysql stored-function or stored-procedure compose
I was wondering if it is possible to execute 'Run Custom Tool' on a
I'm wondering if it's possible to parameterize the sort column in sqlite. I'd like
I'm wondering if it's possible to activate multiple Mono domains and execute them in
I was wondering if it's possible to make an IDE-like application for Android where
I'm new to ruby ... wondering if the following is possible: I currently run
I have something that looks like this: my $report = new ReportGenerator; #custom object

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.