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 9145245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:28:00+00:00 2026-06-17T10:28:00+00:00

My app uses MySQL on one platform and SQLite on another, as such there

  • 0

My app uses MySQL on one platform and SQLite on another, as such there are differences, such as that when using query like DELETE FROM USERS:

  • On MySQL, PreparedStatement.getResultSet() will return null.
  • On SQLite, PreparedStatement.getResultSet() will throw java.sql.SQLException: no ResultSet available.

This may or may not be a bug in SQLite implementation (I think it is supposed to return null), but I have to deal with this somehow.

I could use a try { ... } catch (SQLException e) { ... } and if the exception message is "no ResultSet available", simply return null manually. This doesn’t feel like a right way to do it though.

I could put up an if that makes a check on what JDBC driver is being used and react accordingly, but again, that doesn’t feel like a good solution to the problem.

What I would really like is either a method like .hasResultSet() that returns a boolean OR a way to get the SQL command (SELECT, UPDATE, INSERT etc) from a statement that has been executed. I can find neither of the two in SQL API though.

  • 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-17T10:28:02+00:00Added an answer on June 17, 2026 at 10:28 am

    When executing a query that returns an unknown amount of results, then you need to use execute(). This method returns a boolean indicating the type of result:

    • true: result is a ResultSet
    • false : result is an update count

    If the result is true, then you use getResultSet() to retrieve the ResultSet, otherwise getUpdateCount() to retrieve the update count. If the update count is -1 it means there are no more results. Note that the update count will also be -1 when the current result is a ResultSet. It is also good to know that getResultSet() should return null if there are no more results or if the result is an update count, so the behavior of SQL Lite to throw an exception seems to be wrong.

    Now if you want to retrieve more results, you call getMoreResults() (or its brother accepting an int parameter). The boolean return value of this method has the same meaning as that of execute(), so false does not mean there are no more results!

    There are only no more results if the getMoreResults() returns false and getUpdateCount() returns -1 (as also documented in the Javadoc)

    Essentially this means that if you want to correctly process all results you need to do something like:

    PreparedStatement pstmt = connection.prepareStatement(...);
    // ...
    boolean result = pstmt.execute();
    while(true) {
        if (result) {
            ResultSet rs = pstmt.getResultSet();
            // Do something with resultset ...
        } else {
            int updateCount = pstmt.getUpdateCount();
            if (updateCount == -1) {
                // no more results
                break;
            }
            // Do something with update count ...
        }
        result = pstmt.getMoreResults();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SO I'm working on a schedule app that uses a MySQL DB. One of
I am building a django app that uses SQLAlchemy over MySQL. I am using
I have written a small chat app that uses mysql + php to facilitate
I am working with a fairly old web app that uses MySQL as the
I've made an app in C++ that uses mysql to connect to a server,
OK, I have a web app that uses PHP, MySQL and JavaScript. In an
I have a Rails app whose major part is to query another web-service using
I created an app which uses JPA and MySQL. Now I like to create
I want to migrate my existing desktop Windows .NET 3.5 app. that uses MySQL
I have a Rails app that uses MySQL, MongoDB, NodeJS (and SocketIO). Right now,

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.