如何在Java中使用sql server 2008 R2中的if表执行drop table查询

时间:2016-02-22 04:23:52

标签: java sql-server-2008

我正在尝试在java中运行IF exists' SQL query with statement.executeUpdate(query)。如果我直接在SQL Server管理工作室中运行但是没有使用executeupdate(查询)函数并且给我错误com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.异常,则查询执行正常。

我正在执行的查询是: -

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

任何人都可以告诉我如果我在查询中遗漏了某些内容吗?发布

1 个答案:

答案 0 :(得分:0)

您想使用Statement.execute(String sql)而不是现在执行它的方式。这不期望返回结果集。

如果您有PreparedStatement执行SQL,请使用 PreparedStatement.execute()