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



我正在尝试用java运行IF exists' SQL query with statement.executeUpdate(query)。如果我直接在SQL服务器管理工作室中运行,但无法使用executeupdate(query)功能并给我错误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)而不是你现在执行它的方式。这不需要返回结果集。

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

最新更新