- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用 JDBC 编写一些基本的 PostgreSQL 代码,最终集成到用 Groovy 编写的应用程序中。我编写了这个 Groovy 代码来连接到数据库,然后执行语句;但是,我收到一个错误,我试图找到解决方案,但找不到。以下是 Groovy 代码的相关部分,以及有关错误发生位置的注释:
def sql = Sql.newInstance(dbUrl, dbUser, dbPassword, dbDriver)
println "Sql Instance: " + sql
sql.execute(
" DROP TABLE IF EXISTS test;"
+ "CREATE TABLE test ("
+ "id SERIAL,"
+ "word TEXT,"
+ "number INTEGER,"
+ "decimal NUMERIC,"
+ "datetime TIMESTAMP"
+ ");"
)
def params = ['Hello, World!', 42, 3.14159, null]
sql.execute("INSERT INTO test (word, number, decimal, datetime)"
+ "VALUES (?,?,?,?);", params)
sql.eachRow("SELECT * FROM test;") { row ->
println "The row Id is: ${row.id}"
// HERE??
+ "The word is: ${row.word}"
+ "The number is: ${row.number}"
+ "The decimal is: ${row.decimal}"
+ "The date-time is: ${row.datetime}"
}
sql.close()
控制台日志显示:
Sql Instance: groovy.sql.Sql@5aa9e4eb The row Id is: 1 Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.String.positive() is applicable for argument types: () values: [] Possible solutions: notify(), tokenize(), size(), size() groovy.lang.MissingMethodException: No signature of method: java.lang.String.positive() is applicable for argument types: () values: [] Possible solutions: notify(), tokenize(), size(), size() at DatabaseTest$_run_closure1.doCall(DatabaseTest.groovy:34) at DatabaseTest.run(DatabaseTest.groovy:31) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) Process finished with exit code 1
知道我做错了什么吗?
最佳答案
另一个答案为您提供了我也推荐的解决方案,但仍然知道为什么发生这种情况的原因可能会更好。
Groovy 过度使用运算符重载。这意味着,如果您要编写自己的类,则可以重载 +
运算符来执行许多操作。
但是,在行尾和行首使用 +
是有区别的。
在行尾,+
被视为二元运算符 append
(a + b
),但在行的开头,它被视为一元运算符 正
(+6
被视为“正六”) .
如果你写这个,效果会更好:
println "The row Id is: ${row.id}" +
"The word is: ${row.word}" +
"The number is: ${row.number}" +
"The decimal is: ${row.decimal}" +
"The date-time is: ${row.datetime}"
但是,如果您这样做,您将在一行上获得输出,那是因为您没有添加新行字符,\n
println "The row Id is: ${row.id}\n" +
"The word is: ${row.word}\n" +
"The number is: ${row.number}\n" +
"The decimal is: ${row.decimal}\n" +
"The date-time is: ${row.datetime}"
现在事情开始看起来更难看,这就是为什么 Groovy 的多行字符串功能可以派上用场,如另一个答案所示。
关于Groovy/Postgres "No signature of method: java.lang.String.positive()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31044673/
我在 another question 中遇到此错误消息我想知道签名中的 $: 部分是什么意思? Cannot resolve caller index(Str: Str, Any); none of
Android Studio 2.3 Generate Signed Apk Second Step Signature Verification v1(Jar Signature), v2(Full
我正在尝试使用 PHPMailer 类使用 DKIM 对电子邮件进行签名,但我无法让它工作。 当我在 gmail 上看到我的电子邮件中的 header 时,我发现该类已成功在电子邮件 header 中
我正在尝试 Animal Sniffer . 我已经创建了 .signature 文件。但是要运行 check,我需要一个“签名 Artifact ”。 org.codehaus.mojo.
我想知道 Crypto.Signature.PKCS1_v1_5 和 Crypto.Signature.pkcs1_15 有什么区别? 在documentation他们使用此函数 Crypto.Sig
我正在尝试使用 AWS S3 SDK 上传图片。现在这之前可以工作,但由于某种原因它停止工作并且我开始收到此错误: 现在,当我点击链接时,它给我一个“NoSuchKey”错误: 我不太明白这一点,因为
当 Facebook 发送实时更新时,它们会在 HTTP header 中包含 X-Hub-Signature。根据他们的文档(http://developers.facebook.com/docs/
我正在使用 NuGet 的 Stripe.net SDK。我总是得到 The signature for the webhook is not present in the Stripe-Signat
从 DocumentDB 请求文档时,我偶尔会遇到 UnauthorizedException。该问题看起来类似于 Azure DocumentDB - The MAC signature found
我用我自己的文件替换了不同 dpi 文件夹中的默认 Logo 文件“ic_launcher.png”,也命名为“ic_launcher.png”,但现在我收到此错误: Error: failed to
当 Facebook 发送实时更新时,它们会在 HTTP header 中包含一个 X-Hub-Signature。根据their documentation ,他们使用 SHA1 和应用程序 sec
我有兴趣将带有 RSA 签名的 SHA-1 散列应用于某些数据,但我需要分两步进行 - 首先应用散列,然后对数据进行签名。 Signature.sign() 函数似乎创建了一个更复杂的(ASN.1?)
我将 spring boot 和 spring security 与 JWT on rest 服务一起使用。我使用了以下链接中的代码: https://www.javainuse.com/spring
我正在使用 Stripe 提供的代码来测试 webhook。 Stripe secret 和端点 secret 已经过三重检查。 Stripe 版:6.19 正文解析器:1.19 当我在 Stripe
我有一个调用 Firebase 函数的条纹 webhook。在这个函数中,我需要验证这个请求来自 Stripe 服务器。这是代码: const functions = require('firebas
我已经在网上搜索了两天多,并且可能浏览了大多数在线记录的场景和解决方法,但到目前为止没有任何效果。 我使用的是在 PHP 5.3 上运行的 PHP V2.8.7 的 AWS SDK。 我尝试使用以下代
您好,我正在使用 WooCommerce API - Node.js 客户端 https://www.npmjs.com/package/woocommerce-api 我正在尝试创建一个需要向服务器
我正在尝试创建一个预签名 URL,以帮助某些客户上传文件。这是我当前正在运行的测试脚本 # Get the service client. s3 = boto3.client('s3') boto3.
我编写了一个类,旨在使用服务器上的私钥对文本字符串进行签名和 base64,然后返回签名。每次针对相同文本运行时,它都会生成不同的签名。它为什么要这么做呢?我通过在我的测试机器上暂时禁用转换来检查是否
我们正在使用支持 OAuth 2 多边身份验证的 API。尝试运行我的 rest sharp 客户端 OAuth1Authenticator 实现时出现以下错误: Message: HTTP Stat
我是一名优秀的程序员,十分优秀!