SQLServerException: The statement did not return a result set

Have you ever encountered this exception from executeQuery()? If so, chances are good that your query actually did return a result set (we’ll be addressing the error message text...), but it wasn’t the first result.  Look at your query or stored procedure.  Does it contain multiple SQL statements?  Maybe it includes DDL and DML to create and populate a temp table before the SELECT statement.  If that is the case, then you really need to use execute(), not executeQuery(), to execute it.  The problem is that executeQuery(), per JDBC spec, should only be used with queries whose only result is a single ResultSet.  Quoting from Sun’s documentation of this method:

 

Throws:

SQLException - if a database access error occurs, this method is called on a closed Statement or the given SQL statement produces anything other than a single ResultSet object

 

Some JDBC drivers apparently just ignore and discard DDL and DML results in executeQuery() rather than throwing an exception.

For an explanation on how to use execute() and its partner, getMoreResults(), to execute complex queries, look here.

 

 --David Olix [SQL Server]

This post is provided 'as is' and confers no express or implied warranties or rights.


根据原文意思,如果使用execute然后在通过getMoreResults()来获取结果,或者实用Preparedstatement来实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Microsoft SQL Server 2016: A Beginner’s Guide, Sixth Edition 版本 By 作者: Dusan Petkovic ISBN-10 书号: 1259641791 ISBN-13 书号:: 9781259641794 Edition 版本: 6 Release Finelybook 出版日期: 2016-10-10 pages 页数: (896 ) $45 http://finelybook.com/microsoft-sql-server-2016-a-beginners-guide-6th-edition/ Book Description to Finelybook sorting Up-to-date Microsoft SQL Server 2016 skills made easy! Get up and running on Microsoft SQL Server 2016 in no time with help from this thoroughly revised, practical resource. The book offers thorough coverage of SQL management and development and features full details on the newest business intelligence, reporting, and security features. Filled with new real-world examples and hands-on exercises, Microsoft SQL Server 2016: A Beginner’s Guide, Sixth Edition 版本, starts by explaining fundamental relational database system concepts. From there, you will learn how to write Transact-SQL statements, execute simple and complex database queries, handle system administration and security, and use the powerful analysis and BI tools. XML, spatial data, and full-text search are also covered in this step-by-step tutorial. · Revised from the ground up to cover the latest version of SQL Server · Ideal both as a self-study guide and a classroom textbook · Written by a prominent professor and best-selling author Contents at a Glance Part I Basic Concepts and Installation Chapter 1 Relational Database Systems: An Introduction Chapter 2 Planning the Installation and Installing SQL Server Chapter 3 SQL Server Management Studio Part II Transact-SQL Language 语言 Chapter 4 SQL Components Chapter 5 Data Definition Language 语言 Chapter 6 Queries Chapter 7 Modification of a Table’s Contents Chapter 8 Stored Procedures and User-Defined Functions Chapter 9 System Catalog Chapter 10 Indices Chapter 11 Views Chapter 12 Security System of the Database Engine Chapter 13 Concurrency Control Chapter 14 Triggers Part III SQL Server: System Administration Chapter 15 System Environment of the Database Engine Chapter 16 Backup, Recovery, and System Availability Chapter 17 Automating System Administration Tasks Chapter 18 Data Replication Chapter 19 Query Optimizer Chapter 20 Performance Tuning Chapter 21 In-Memory OLTP Part IV SQL Server and Business Intelligence Chapter 22 Business Intelligence: An Introduction Chapter 23 SQL Server Analysis Services Chapter 24 Business Intelligence and Transact-SQL Chapter 25 SQL Server Reporting Services Chapter 26 Optimizing Techniques for Data Warehousing Chapter 27 Columnstore Indices Part V Beyond Relational Data Chapter 28 XML and JSON Integration in the Database Engine Chapter 29 Spatial and Temporal Data Chapter 30 SQL Server Full-Text Search

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值