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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:19:01+00:00 2026-06-14T00:19:01+00:00

I’ve been searching google and stack overflow for the past several hours, and can’t

  • 0

I’ve been searching google and stack overflow for the past several hours, and can’t seem to find an exact match on this issue. I’m relatively new to java, so please correct me if I’m just doing something incredibly silly!

Issue: When executing a try-with-resource query (statement.executeQuery(stmt)) I am getting a ‘Statement did not return a result set’

I can guarantee this is valid SQL, and when run through SSMS the query works – and when using the select…into…from style syntax, this query works as well [in java]. The select…into…from is not a viable option though as it creates performance issues (23 second query turns into a 5+ minute query due to resource utilization)

Proof of concept:
SQL file: c:\test.sql

set nocount on
create table #test (loannum int)
insert into #test (loannum)
select 1
select * from #test
drop table #test

This query is used to make a cached result set so that I can pass the data around other functions without leaving an open connection to the database…

Note: SQLInfo in the below is just “C:\test.sql”
< snip>

try(BufferedReader in = new BufferedReader(new FileReader(SQLInfo)))
                {
                    String str;
                    StringBuffer sb = new StringBuffer();
                    while((str = in.readLine()) != null)
                    {
                        sb.append(str + System.getProperty("line.separator"));
                    }

                    _stmt = sb.toString();
                }

< /snip>

which is later used in the below…
< snip>

try (Connection connection = DriverManager.getConnection(CONNECTION);
                Statement statement = connection.createStatement();
                ResultSet resultset = statement.executeQuery(_stmt)
            ) 
        {

            crs.populate(resultset);

            return crs;
        }
        catch (SQLException e) 
        {
            e.printStackTrace();
        }
        return crs;

< /snip>

What I’m expecting, is a cached result set that will be used in a defaulttablemodel to display a “loannum” field, and value of 1 — what I really get is the following error: “com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set…”

If I modify the SQL to the following:

set nocount on
select 1 as loannum
into #test
select * from #test
drop table #test

I get the expected return result of “loannum” with value of 1.

It appears to have something to do with the create table statement in the executeQuery method, but it’s a temporary table! Is there any way to make the above to work with the create table (value type, value type, value type) insert into… method?

**Note: I’ve attempted to use the .execute(String) method, and parse through the return results. It appears to have the same issue, but it’s entirely possible I’m implementing it incorrectly.

**Secondary note: The defaulttablemodel works fine, and returns information to a JTable that displays on screen. This dynamically allocates the column names, and displays the associated values. I can provide a sample of this code if needed, but i don’t think it’s relevant to the issue as this is failing on simply creating the resultset, rather then when it’s trying to assign the information to the table model.

[Editing this in]: Stored procedures on SQL side are not a viable option in this instance. This is a query against a data warehouse that does not allow stored procs as company policy (I’ve pushed back, and have been smacked down) – As a result, I’m working on this … hackish solution.

Hopefully somebody has some insight into this issue!

  • 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-14T00:19:02+00:00Added an answer on June 14, 2026 at 12:19 am

    As it turns out, after I updated to use the execute command, I had accidentally included it into a try-with-resources block, resulting in returning a closed dataset to the calling function, which would then error with an empty resultset passed to create the default table model. Whoops.

    Ultimately, the execute query worked with the following (refactoring and cleanup still necessary, this was just ‘get it working’):

    try 
            {
                boolean hasResults = statement.execute(_stmt);
    
                do { //I think... this could only possibly get one result. FIXME
    
                if (hasResults) 
                {
                    try(ResultSet rs = statement.getResultSet())
                    {
                        CachedRowSetImpl crs = new CachedRowSetImpl();
                        crs.populate(rs);
    
                        return crs;
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
    
                hasResults = statement.getMoreResults();
    
                } while (hasResults || statement.getUpdateCount() != -1);
    
                } 
            catch (Exception e) 
            {
                e.printStackTrace();
            } 
            finally 
            {
                statement.close();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.