在第一种情况下使用DBUtils时出错 [英] Error using DBUtils in first scenario

查看:90
本文介绍了在第一种情况下使用DBUtils时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Eclipse中使用DBUtils.java并在其中运行测试时,它可以正常工作,但是当我通过Jenkins运行它时,第一次使用DBUtils失败.第二个作品... 第一次使用db.readRows失败.

When I use DBUtils.java in Eclipse and run the tests there it works fine, but when I run it through Jenkins the first time that DBUtils are used is failing. And the second works... The first time that it uses db.readRows it fails.

    Scenario: Account Create

    Given path 'accounts'
    And header Authorization = setup.authorization
    And request {identifier: KarateCreation, subscribers:[{identifier:KarateCreation, firstName:KarateCreation, lastName:KarateCreation}]}
    When method POST
    And match response contains { id: '#number', identifier: KarateCreation }
    Then status 201

    * def id = response.id
    * def accountNumber = response.identifier

    # use jdbc to validate
    * def config = { url: #(dbConnectionString), driverClassName: 'oracle.jdbc.OracleDriver' }
    * def DbUtils = Java.type('restapi.util.DbUtils')
    * def db = new DbUtils(config)

    * def rs = db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")
    * match rs contains { ACCOUNTID: '#(id)', ACCOUNTNUMBER: KarateCreation }

错误:

   * def rs = db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")(Scenario: Account Create)  Time elapsed: 0.039 sec  <<< ERROR!
  java.lang.RuntimeException: javascript evaluation failed: db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")
at com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:115)
at com.intuit.karate.ScriptBindings.updateBindingsAndEval(ScriptBindings.java:103)
at com.intuit.karate.ScriptBindings.evalInNashorn(ScriptBindings.java:88)
at com.intuit.karate.Script.evalJsExpression(Script.java:362)
at com.intuit.karate.Script.evalKarateExpression(Script.java:284)
at com.intuit.karate.Script.evalKarateExpression(Script.java:170)
at com.intuit.karate.Script.assign(Script.java:598)
at com.intuit.karate.Script.assign(Script.java:524)
at com.intuit.karate.StepDefs.def(StepDefs.java:305)
at ✽.* def rs = db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")(restapi/accounts/accounts.feature:31)
  Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLRecoverableException: IO Error: Connection reset

推荐答案

首先,我谨提醒您,DBUtils.java是作为演示示例创建的,并不属于空手道的核心.由于类似这样的问题,我开始后悔把它放在那里.参见另一个示例.

First may I gently remind you that DBUtils.java was created as a demo example and is not part of the core of Karate. I am beginning to regret having put this there because of questions like this. See another example.

编辑-由于出现了很多问题:您应该编写自己的代码以连接到数据库,执行SQL并以所需的方式解压缩结果.请不要将与此相关的问题标记为"karate".

EDIT - Since this question comes up a lot: You are expected to write your own code to connect to your database, execute SQL and unpack the results the way you want. Please don't tag questions around this as "karate".

无论如何,请与您的团队或组织中的某人一起解决此问题:

Anyway, please work with somebody in your team or org to fix this problem:

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: 
Could not get JDBC Connection; nested exception is
java.sql.SQLRecoverableException: IO Error: Connection reset

您的Jenkins机器很可能无法建立与数据库的连接,并且端口被防火墙隔离等.

It is quite possible that your Jenkins box is not able to establish a connection to the database and the ports are fire-walled off etc.

这篇关于在第一种情况下使用DBUtils时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆