<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="it">
	<id>http://wiki.netsitech.com/index.php?action=history&amp;feed=atom&amp;title=Programmazione%3AJava%2FJDBC%2FMSSQL_stored_procedure</id>
	<title>Programmazione:Java/JDBC/MSSQL stored procedure - Cronologia</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.netsitech.com/index.php?action=history&amp;feed=atom&amp;title=Programmazione%3AJava%2FJDBC%2FMSSQL_stored_procedure"/>
	<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/JDBC/MSSQL_stored_procedure&amp;action=history"/>
	<updated>2026-05-08T22:15:53Z</updated>
	<subtitle>Cronologia della pagina su questo sito</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://wiki.netsitech.com/index.php?title=Programmazione:Java/JDBC/MSSQL_stored_procedure&amp;diff=3247&amp;oldid=prev</id>
		<title>Mazzotti il 10:48, 24 set 2009</title>
		<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/JDBC/MSSQL_stored_procedure&amp;diff=3247&amp;oldid=prev"/>
		<updated>2009-09-24T10:48:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;it&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versione meno recente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Versione delle 10:48, 24 set 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l27&quot; &gt;Riga 27:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Riga 27:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * &amp;lt;p/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * &amp;lt;p/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * This exception is due to this version (and later) of the driver returning additional update counts before&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * This exception is due to this version (and later) of the driver returning additional update counts before&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * returning a result set, thus requiring &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;code&amp;gt;&lt;/del&gt;getMoreResults()&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/code&amp;gt; &lt;/del&gt;to be called in client code one or more&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * returning a result set, thus requiring getMoreResults() to be called in client code one or more&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * times before the result set can be accessed. This method calls &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;code&amp;gt;&lt;/del&gt;getMoreResults()&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/code&amp;gt; &lt;/del&gt;as necessary until&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * times before the result set can be accessed. This method calls getMoreResults() as necessary until&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * the result set becomes accessible.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * the result set becomes accessible.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   *&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   *&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Mazzotti</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.netsitech.com/index.php?title=Programmazione:Java/JDBC/MSSQL_stored_procedure&amp;diff=3246&amp;oldid=prev</id>
		<title>Mazzotti il 10:46, 24 set 2009</title>
		<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/JDBC/MSSQL_stored_procedure&amp;diff=3246&amp;oldid=prev"/>
		<updated>2009-09-24T10:46:08Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;it&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versione meno recente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Versione delle 10:46, 24 set 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l23&quot; &gt;Riga 23:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Riga 23:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * This utility method is designed to work around the complexity of retrieving result sets from stored procedures in&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * This utility method is designed to work around the complexity of retrieving result sets from stored procedures in&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * Microsoft SQL Server databases using the Microsoft JDBC driver 1.2.xx and later, where calling&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * Microsoft SQL Server databases using the Microsoft JDBC driver 1.2.xx and later, where calling&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;code&amp;gt;&lt;/del&gt;Statement.executeQuery()&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/code&amp;gt; &lt;/del&gt;with this driver throws an exception saying &amp;quot;The statement did not return a&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * Statement.executeQuery() with this driver throws an exception saying &amp;quot;The statement did not return a&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * result set&amp;quot;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * result set&amp;quot;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * &amp;lt;p/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   * &amp;lt;p/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Mazzotti</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.netsitech.com/index.php?title=Programmazione:Java/JDBC/MSSQL_stored_procedure&amp;diff=3245&amp;oldid=prev</id>
		<title>Mazzotti: Creata pagina con 'A partire dalla versione 1.2 del driver JDBC Microsoft, la chiamata ad una stored procedure che ritorna in ResultSet, genera una eccezione del tipo &quot;The statement did not return …'</title>
		<link rel="alternate" type="text/html" href="http://wiki.netsitech.com/index.php?title=Programmazione:Java/JDBC/MSSQL_stored_procedure&amp;diff=3245&amp;oldid=prev"/>
		<updated>2009-09-24T10:45:08Z</updated>

		<summary type="html">&lt;p&gt;Creata pagina con &amp;#039;A partire dalla versione 1.2 del driver JDBC Microsoft, la chiamata ad una stored procedure che ritorna in ResultSet, genera una eccezione del tipo &amp;quot;The statement did not return …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nuova pagina&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A partire dalla versione 1.2 del driver JDBC Microsoft, la chiamata ad una stored procedure che ritorna in ResultSet, genera una eccezione del tipo &amp;quot;The statement did not return a result set&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
CallableStatement cs = conn.prepareCall(&amp;quot;{CALL prSomeProcedure()}&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
ResultSet rs = cs.executeQuery(); // Exception thrown here: &amp;quot;The statement did not return a result set&amp;quot;.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
La soluzione del problema sta nel rimpiazzare il codice sopra-indicato con questo:&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
CallableStatement cs = conn.prepareCall(&amp;quot;{CALL prSomeProcedure()}&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
ResultSet rs = DBUtil.executeStatementAndRetrieveResultSet(cs); // Exception not thrown here :)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
dove il blocco di codice che ottiene il ResultSet è il seguente:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code java&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
  * Executes a callable statement which has been prepared to call a stored procedure which returns a result set, and&lt;br /&gt;
  * returns the first result set found.&lt;br /&gt;
  * &amp;lt;p/&amp;gt;&lt;br /&gt;
  * This utility method is designed to work around the complexity of retrieving result sets from stored procedures in&lt;br /&gt;
  * Microsoft SQL Server databases using the Microsoft JDBC driver 1.2.xx and later, where calling&lt;br /&gt;
  * &amp;lt;code&amp;gt;Statement.executeQuery()&amp;lt;/code&amp;gt; with this driver throws an exception saying &amp;quot;The statement did not return a&lt;br /&gt;
  * result set&amp;quot;.&lt;br /&gt;
  * &amp;lt;p/&amp;gt;&lt;br /&gt;
  * This exception is due to this version (and later) of the driver returning additional update counts before&lt;br /&gt;
  * returning a result set, thus requiring &amp;lt;code&amp;gt;getMoreResults()&amp;lt;/code&amp;gt; to be called in client code one or more&lt;br /&gt;
  * times before the result set can be accessed. This method calls &amp;lt;code&amp;gt;getMoreResults()&amp;lt;/code&amp;gt; as necessary until&lt;br /&gt;
  * the result set becomes accessible.&lt;br /&gt;
  *&lt;br /&gt;
  * @param cs A callable statement which has been prepared to call a stored procedure which returns a result set.&lt;br /&gt;
  *&lt;br /&gt;
  * @return The first (or only) result set returned by the statement.&lt;br /&gt;
  * @throws IllegalArgumentException If the callable statement specified is null.&lt;br /&gt;
  * @throws SQLException If any error occurs.&lt;br /&gt;
  */&lt;br /&gt;
protected ResultSet executeStatementAndRetrieveResultSet(CallableStatement cs) throws SQLException {&lt;br /&gt;
    if (cs == null) {&lt;br /&gt;
        throw new IllegalArgumentException(&amp;quot;The callable statement specified was null.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    // Execute the statement...&lt;br /&gt;
    boolean resultSetFound;&lt;br /&gt;
    try {&lt;br /&gt;
        resultSetFound = cs.execute();&lt;br /&gt;
    }&lt;br /&gt;
    catch (Exception e) {&lt;br /&gt;
        SQLException sqle = new SQLException(&amp;quot;Failed to execute the statement: &amp;quot; + e);&lt;br /&gt;
        sqle.initCause(e);&lt;br /&gt;
        throw sqle;&lt;br /&gt;
    }&lt;br /&gt;
    // Retrieve the first result set from the statement...&lt;br /&gt;
    try {&lt;br /&gt;
        while (!resultSetFound) {&lt;br /&gt;
            resultSetFound = cs.getMoreResults();&lt;br /&gt;
            // Check if there are no more results...&lt;br /&gt;
            if (!resultSetFound &amp;amp;&amp;amp; cs.getUpdateCount() == -1) {&lt;br /&gt;
                // No more result sets are available. Stop searching...&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            // Else continue looking for a result set...&lt;br /&gt;
        }&lt;br /&gt;
        if (resultSetFound) {&lt;br /&gt;
            ResultSet rs = cs.getResultSet();&lt;br /&gt;
            if (rs == null) {&lt;br /&gt;
                throw new IllegalStateException(&amp;quot;Unexpectedly failed to retrieve a result set from statement.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            return rs;&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
            throw new SQLException(&amp;quot;Scanned all results returned by the statement but did not find a result set.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    catch (Exception e) {&lt;br /&gt;
        SQLException sqle = new SQLException(&amp;quot;Executed the statement but failed to retrieve a result set: &amp;quot; + e);&lt;br /&gt;
        sqle.initCause(e);&lt;br /&gt;
        throw sqle;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mazzotti</name></author>
		
	</entry>
</feed>