尝试使用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实例:groovy.sql.Sql@5aa9e4eb 行Id为:1 捕捉到错误:groovy.lang.MissingMethodException: No signature of method: java.lang.String.positive() is applicable for argument types: () values: [] 可能的解决方案包括:notify(),tokenize(),size(),size() groovy.lang.MissingMethodException: No signature of method: java.lang.String.positive() is applicable for argument types: () values: [] 可能的解决方案包括: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)
进程以退出代码1结束
你有什么想法,我在哪里出了问题?