簡體   English   中英

如何在Java中的SQL Server 2008 R2中使用存在的表執行刪除表查詢

[英]How to execute drop table query with if exists in sql server 2008 R2 in Java

我正在嘗試IF exists' SQL query with statement.executeUpdate(query) Java中的IF exists' SQL query with statement.executeUpdate(query)運行IF exists' SQL query with statement.executeUpdate(query) 如果我直接在SQL Server Management Studio中運行,但不能與executeupdate(query)函數一起使用,並給我錯誤com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.則查詢執行正常com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set. 例外。

我正在執行的查詢是:

 IF EXISTS(select * from sysobjects where name='tblname') drop table tblname

有人可以讓我知道是否在查詢中遺漏了什么嗎?

您想使用Statement.execute(String sql)而不是現在執行它的方式。 這不希望返回結果集。

如果你有一個PreparedStatement在其上執行SQL,使用PreparedStatement.execute()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM