0

我正在使用这个 Spring Boot 应用程序。在这里,我需要获取 MS SQL 数据库中表的行数。

    private static final String GET_TOTAL_DATA_COUNT = "SELECT COUNT(1) FROM :tableName ";


    @Override
    public Integer getTotalDataCount() {

        SqlParameterSource namedParameter = new MapSqlParameterSource().addValue("tableName", "SYSCORPP.R71DB2.VEND_VNXR_TABLE");
        return namedParamJdbcTemplate.queryForObject(GET_TOTAL_DATA_COUNT, namedParameter, Integer.class);

    }

运行此程序时,我收到一条错误消息,提示我需要声明变量 @P0。

PreparedStatementCallback; uncategorized SQLException for SQL [SELECT COUNT(1) FROM @P0]; SQL state [S0002]; error code [1087]; Must declare the table variable "@P0".; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Must declare the table variable "@P0". org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT COUNT(1) FROM @P0]; SQL state [S0002]; error code [1087]; Must declare the table variable "@P0".; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Must declare the table variable "@P0". 

有没有人知道如何解决这个问题?

4

0 回答 0