Re: Bug with Multiple Result Sets?
- From: "Angel Saenz-Badillos[MS]" <angelsa@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 1 Feb 2006 13:06:30 -0800
Just a quick note, please do not post connection string information in the newsgroups. I will let Evan handle this issue, it looks interesting. Thank you, -- Angel Saenz-Badillos [MS] DataWorks This posting is provided "AS IS", with no warranties, and confers no rights.Please do not send email directly to this alias. This alias is for newsgroup purposes only. I am now blogging: http://weblogs.asp.net/angelsb/ "Wes Clark" <WesClark@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:461F7166-63ED-4C52-85CE-C08A52F2E576@xxxxxxxxxxxxxxxx > New program and results below. The new driver is getting "results" > interleaved with result sets. The doc for "getMoreResults" is " Moves to > this Statement > > import java.sql.*; > > public class MultipleResultSets { > public MultipleResultSets() { > } > > public static void main(String[] args) { > try { > System.out.println("Trying the 2005 driver against the 2005 > database"); > System.out.println("Class being loaded > com.microsoft.sqlserver.jdbc.SQLServerDriver"); > > java.lang.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); > String url = > "jdbc:sqlserver://ALKOR:1434;selectMethod=direct;databaseName=AdventureWorks;user=sa;password=456"; > System.out.println("URL being used: " + url); > Connection conn = java.sql.DriverManager.getConnection(url); > String sql = "dbcc show_statistics([Person.Address], > PK_Address_AddressID)"; > System.out.println("== First way =="); > processMultipleResultSetsFirstWay(conn, sql); > System.out.println("== Second way =="); > processMultipleResultSetsSecondWay(conn, sql); > conn.close(); > } catch (ClassNotFoundException e) { > e.printStackTrace(); //To change body of catch statement use File | > Settings | File Templates. > } catch (SQLException e) { > e.printStackTrace(); //To change body of catch statement use File | > Settings | File Templates. > } > try { > System.out.println("Trying the 2005 driver against the 2000 > database"); > System.out.println("Class being loaded > com.microsoft.sqlserver.jdbc.SQLServerDriver"); > > java.lang.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); > String url = > "jdbc:sqlserver://ALKOR:1433;selectMethod=direct;databaseName=Pubs;user=sa;password=123"; > System.out.println("URL being used: " + url); > Connection conn = java.sql.DriverManager.getConnection(url); > String sql = "dbcc show_statistics(authors, aunmind)"; > Statement stmt = conn.createStatement(); > System.out.println("== First way =="); > processMultipleResultSetsFirstWay(conn, sql); > System.out.println("== Second way =="); > processMultipleResultSetsSecondWay(conn, sql); > conn.close(); > } catch (ClassNotFoundException e) { > e.printStackTrace(); > } catch (SQLException e) { > e.printStackTrace(); > } > try { > System.out.println("Trying the 2000 driver against the 2000 > database"); > System.out.println("Class being loaded > com.microsoft.jdbc.sqlserver.SQLServerDriver"); > > java.lang.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); > String url = > "jdbc:microsoft:sqlserver://ALKOR:1433;databaseName=pubs;user=sa;password=123;"; > System.out.println("URL being used: " + url); > Connection conn = java.sql.DriverManager.getConnection(url); > String sql = "dbcc show_statistics(authors, aunmind)"; > System.out.println("== First way =="); > processMultipleResultSetsFirstWay(conn, sql); > System.out.println("== Second way =="); > processMultipleResultSetsSecondWay(conn, sql); > conn.close(); > } catch (ClassNotFoundException e) { > e.printStackTrace(); > } catch (SQLException e) { > e.printStackTrace(); > } > try { > System.out.println("Trying the 2000 driver against the 2005 > database"); > System.out.println("Class being loaded > com.microsoft.jdbc.sqlserver.SQLServerDriver"); > > java.lang.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); > String url = > "jdbc:microsoft:sqlserver://ALKOR:1434;databaseName=AdventureWorks;user=sa;password=456;"; > System.out.println("URL being used: " + url); > Connection conn = java.sql.DriverManager.getConnection(url); > String sql = "dbcc show_statistics([Person.Address], > PK_Address_AddressID)"; > System.out.println("== First way =="); > processMultipleResultSetsFirstWay(conn, sql); > System.out.println("== Second way =="); > processMultipleResultSetsSecondWay(conn, sql); > conn.close(); > } catch (ClassNotFoundException e) { > e.printStackTrace(); > } catch (SQLException e) { > e.printStackTrace(); > } > > } > > public static void processMultipleResultSetsFirstWay(Connection conn, > String sql) { > try { > Statement stmt = conn.createStatement(); > stmt.execute(sql); > int updateCount = stmt.getUpdateCount(); > System.out.println("Update count is " + updateCount); > ResultSet rs = stmt.getResultSet(); > System.out.println("Is first result set null? " + (rs == null ? "Yes, > null" : "No, not null")); > boolean moreResults = stmt.getMoreResults(); > System.out.println("stmt.getMoreResults() returns " + moreResults); > if (moreResults) { > rs = stmt.getResultSet(); > System.out.println("Is second result set null? " + (rs == null ? > "Yes, null" : "No, not null")); > moreResults = stmt.getMoreResults(); > System.out.println("stmt.getMoreResults() returns " + moreResults); > if (moreResults) { > rs = stmt.getResultSet(); > System.out.println("Is third result set null? " + (rs == null ? > "Yes, null" : "No, not null")); > moreResults = stmt.getMoreResults(); > System.out.println("stmt.getMoreResults() returns " + > moreResults); > } > } > } catch (SQLException e) { > e.printStackTrace(); > } > } > > public static void processMultipleResultSetsSecondWay(Connection conn, > String sql) { > try { > Statement stmt = conn.createStatement(); > boolean aResultSetIsNext = stmt.execute(sql); > int updateCount = -1; > while (true) { // handle all in-line results from any procedure > if (aResultSetIsNext) { > ResultSet r = stmt.getResultSet(); > System.out.println("We got a valid result set..."); > while (r.next()) { > // process result set > } > r.close(); > } else { > updateCount = stmt.getUpdateCount(); > if (updateCount != -1) { > System.out.println("Got a valid update count = " + > updateCount); > } > } > if ((!aResultSetIsNext) && (updateCount == -1)) break; // done with > loop > aResultSetIsNext = stmt.getMoreResults(); > } > System.out.println("Done with inline returns"); > // For CallableStatements, get output parameters now... > stmt.close(); > } catch (SQLException e) { > e.printStackTrace(); //To change body of catch statement use File | > Settings | File Templates. > } > } > } > > Results: > Trying the 2005 driver against the 2005 database > Class being loaded com.microsoft.sqlserver.jdbc.SQLServerDriver > URL being used: > jdbc:sqlserver://ALKOR:1434;selectMethod=direct;databaseName=AdventureWorks;user=sa;password=456 > == First way == > Update count is -1 > Is first result set null? No, not null > stmt.getMoreResults() returns false > == Second way == > We got a valid result set... > Got a valid update count = 1 > We got a valid result set... > Got a valid update count = 1 > We got a valid result set... > Got a valid update count = 5 > Got a valid update count = 0 > Done with inline returns > Trying the 2005 driver against the 2000 database > Class being loaded com.microsoft.sqlserver.jdbc.SQLServerDriver > URL being used: > jdbc:sqlserver://ALKOR:1433;selectMethod=direct;databaseName=Pubs;user=sa;password=123 > == First way == > Update count is -1 > Is first result set null? No, not null > stmt.getMoreResults() returns false > == Second way == > We got a valid result set... > Got a valid update count = 1 > We got a valid result set... > Got a valid update count = 3 > We got a valid result set... > Got a valid update count = 22 > Got a valid update count = 0 > Done with inline returns > Trying the 2000 driver against the 2000 database > Class being loaded com.microsoft.jdbc.sqlserver.SQLServerDriver > URL being used: > jdbc:microsoft:sqlserver://ALKOR:1433;databaseName=pubs;user=sa;password=123; > == First way == > Update count is -1 > Is first result set null? No, not null > stmt.getMoreResults() returns true > Is second result set null? No, not null > stmt.getMoreResults() returns true > Is third result set null? No, not null > stmt.getMoreResults() returns false > == Second way == > We got a valid result set... > We got a valid result set... > We got a valid result set... > Done with inline returns > Trying the 2000 driver against the 2005 database > Class being loaded com.microsoft.jdbc.sqlserver.SQLServerDriver > URL being used: > jdbc:microsoft:sqlserver://ALKOR:1434;databaseName=AdventureWorks;user=sa;password=456; > == First way == > Update count is -1 > Is first result set null? No, not null > stmt.getMoreResults() returns true > Is second result set null? No, not null > stmt.getMoreResults() returns true > Is third result set null? No, not null > stmt.getMoreResults() returns false > == Second way == > We got a valid result set... > We got a valid result set... > We got a valid result set... > Done with inline returns .
- Follow-Ups:
- Re: Bug with Multiple Result Sets?
- From: Evan T. Basalik (MSFT)
- Re: Bug with Multiple Result Sets?
- Prev by Date: Re: Setting the Isolation Level in the Connection Properties
- Next by Date: Re: Windows Security not provided?
- Previous by thread: Re: Setting the Isolation Level in the Connection Properties
- Next by thread: Re: Bug with Multiple Result Sets?
- Index(es):
Relevant Pages
|
Loading