在SpringBoot应用程序中执行CallableStatement时卡住

时间:2019-04-17 10:41:39

标签: java oracle spring-boot callable-statement

当我将CallableStatement运行到PL / SQL DB时,它被卡住了。我认为这是一个主线程问题,但我不知道如何解决。

我的OracleService班:

@Service
public class OracleService {

    private static final Logger LOG = LoggerFactory.getLogger(OracleService.class);

    private static final String PROCEDURE = "{ call <USER>.<PACKAGE>.<PROCEDURE_NAME>(?, ?) }";

    @Autowired
    private OracleConfig oracleConfig;

    public void testProcedure() {

        try (Connection connection = oracleConfig.connection()) {
            connection.setAutoCommit(true);

            CallableStatement callableStatement = connection.prepareCall(PROCEDURE);

            int index = 1;

            Date currDate = new Date();
            callableStatement.setDate(index++, new java.sql.Date(currDate.getTime()));
            callableStatement.registerOutParameter(index++, OracleTypes.CURSOR);

            callableStatement.execute(); // Here it is getting stucked

            // Processing data
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}

它由CommandLineRunner类中的简单Application调用:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    CommandLineRunner lookup() {
        return args -> {
                    OracleService service = new OracleService();
                    service.testProcedure();
         };
    }
}

如果有人知道,请帮助我

1 个答案:

答案 0 :(得分:0)

非常感谢对评论做出回应的人。愚蠢的问题与等待客户端更新的SQL语句有关。小心=)

P.S .:如@ M.Deinum所述,使用Spring时,更好的做法是从Connection的池中检索JdbcTemplate s