简体   繁体   English

如何在Java中的SQL Server 2008 R2中使用存在的表执行删除表查询

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

I am trying to run an IF exists' SQL query with statement.executeUpdate(query) 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) Query executes fine if I directly run in SQL server management studio but did not work with executeupdate(query) function and gave me the error com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set. 如果我直接在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. exception. 例外。

The Query which I am executing is:- 我正在执行的查询是:

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

Can anyone let me know If I am missing something in the query?post 有人可以让我知道是否在查询中遗漏了什么吗?

You want to use Statement.execute(String sql) instead of the way you are executing it now. 您想使用Statement.execute(String sql)而不是现在执行它的方式。 This doesn't expect a resultset be returned. 这不希望返回结果集。

If you have a PreparedStatement on which you execute the SQL, use PreparedStatement.execute() . 如果你有一个PreparedStatement在其上执行SQL,使用PreparedStatement.execute()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM